Category Archives: JAVA

Floating point manipulation in Java

Hi All,

Today, I am writing on a very interesting topic “How floating points are handled in java in JAVA?”  Have you ever tried multiplying any two double like:

0.1*0.4

what do you expect the output should be?  0.04? No, that’s not the case, its 0.04000000000000001 crazy 😀

The reason why it is happening is the way double are handled in JAVA. So, to make it easy let us consider above example and understand step by step how double is handled and how JVM managed to give this output.

All floating numbers in Java follow IEEE 754 Double-precision  floating-point format.

Continue reading