Why does the happen in floating point?
There are several unexpected things that seem to bite programmers with floating point. This is almost always a result of the programmer not being fully conversant with floating point arithmetic in general, rather than a problem relating to Java technology. The question of floating point accuracy comes up more than with C++ (for example) because of Sun’s decision in the println() method to print enough digits to distinguish the number from the next-closest number, rather than rounding it to 6 significant digits by default as the C/C++ libraries do. [ISO C, Sect 7.9.6.1, line 21 of “the double argument”] If you seem to be having problems with floating point, the problem probably stems from the fact that floating-point arithmetic is inherently imprecise. You can expect up to 7 digits of precision with floats and 16 digits with doubles. However, that does not mean that a number that can be exactly represented in 7 digits decimal or can be exactly represented as a binary floating point numb
There are several unexpected things that seem to bite programmers with floating point. This is almost always a result of the programmer not being fully conversant with floating point arithmetic in general, rather than a problem relating to Java technology. The question of floating point accuracy comes up more than with C++ (for example) because of Sun’s decision in the println() method to print enough digits to distinguish the number from the next-closest number, rather than rounding it to 6 significant digits by default as the C/C++ libraries do. [ISO C, Sect 7.9.6.1, line 21 of “the double argument”] If you seem to be having problems with floating point, the problem probably stems from the fact that floating-point arithmetic is inherently imprecise. You can expect up to 7 digits of precision with floats and 16 digits with doubles.
[*] There are several unexpected things that seem to bite programmers with floating point. This is almost always a result of the programmer not being fully conversant with floating point arithmetic in general, rather than a problem relating to Java. The question of floating point accuracy comes up with Java more than with C++ (for example) because of Java’s decision in the println() method to print enough digits to distinguish the number from the next-closest number, rather than rounding it to 6 significant digits by default as the C/C++ libraries do. [ISO C, Sect 7.9.6.1, line 21 of “the double argument”] If you seem to be having problems with floating point, the problem probably stems from the fact that floating-point arithmetic is inherently imprecise. You can expect up to 7 digits of precision with floats and 16 digits with doubles. However, that does not mean that a number that can be exactly represented in 7 digits decimal or can be exactly represented as a binary floating point