I have read this - Why Are Floating Point Numbers Inaccurate?
So, sometimes precision can be changed in floating point number because of it's representation style (scientific notation with an exponent and a mantissa).
int i = 3; double d = (double) i; System.out.println(d);
the output I got
3.0 as I expected.
but, is there any chance of being precision changed like
3.000001 because of representation style of double in java?
Not for int to double, but you might for long to double (or int to float):
- Not all longs greater than
2^53-1(or less than
-2^53) can be represented exactly by a double;
- Not all ints greater than
2^24-1(or less than
-2^24) can be represented exactly by a float.
This restriction comes about because of the number of bits used to represent the mantissa (53 in doubles, 24 in floats).