What is the result of this code execution:

System.out.println( 0.1d );
Most fractional numbers can not be accurately represented by a double type. For example, 0.1 in the binary form is represented as an infinite binary fraction, as in the computer memory only a limited number of places is stored, the infinite "tail" is discarded and the resulting value slightly differs from 0.1.
This way of representing the fractional numbers is included in the output to the screen and displays the "correct" value. If you use another way to represent fractional numbers, you can get a different result.
For example, the command System.out.println(new BigDecimal(0.1)); will bring real insight of the number in the memory:

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback