2

I executed the below for loop,

for(double i = -1.0;i <=1.0;i=i+0.1)
      System.out.println(i);

O/P:

-1.0
-0.9
-0.8
-0.7000000000000001
-0.6000000000000001
-0.5000000000000001
-0.40000000000000013
-0.30000000000000016
-0.20000000000000015
-0.10000000000000014
-1.3877787807814457E-16
0.09999999999999987
0.19999999999999987
0.2999999999999999
0.3999999999999999
0.4999999999999999
0.5999999999999999
0.6999999999999998
0.7999999999999998
0.8999999999999998
0.9999999999999998

In the middle before 0.0 getting a weird -1.3877787807814457E-16.

There is no exact representation of the decimal points in binary, but there should be a relevance. This -1.3877787807814457E-16 does not related to any values between -0.1 to 0.0.

why this value is computed ?

0 Answers0