assign int to byte vs double to float in java

后端 未结 3 2009
粉色の甜心
粉色の甜心 2020-12-16 07:15

1.when we assign double to float variable compiler gives us error

float f = 2753.2211;

possible loss of precision<

3条回答
  •  甜味超标
    2020-12-16 08:05

    int is a 32-bit signed integer, byte is an 8-bit signed integer. A byte runs from -128 to 127, while a int runs from -2147483648 to 2147483647

    Precision isn't lost, but do not cast a big int into a small byte or you will lose data.

提交回复
热议问题