Loss of precision – int -> float or double

In Java Integer uses 32 bits to represent its value.

In Java a FLOAT uses a 23 bit mantissa, so integers greater than 2^23 will have their least significant bits truncated. For example 33554435 (or 0x200003) will be truncated to around 33554432 +/- 4

In Java a DOUBLE uses a 52 bit mantissa, so will be able to represent a 32bit integer without lost of data.

See also “Floating Point” on wikipedia

Leave a Comment