2 ms·
The problem is that the decimal numbers in IEEE-754 are approximated by fractions where the denominator is a power of 2. So 1.15 =~ 5179139571476070 / 2**5
by gus_massa 15y ago
The problem is that the decimal numbers in IEEE-754 are approximated by fractions where the denominator is a power of 2.
So
1.15 =~ 5179139571476070 / 2**52
= 5179139571476070 / 4503599627370496
=~ 1.1499999999999999111821580299875...
And then
1.15*100 =~ (5179139571476070 / 2**52) * 100
= 5179139571476070 / 4503599627370496 *100
=~ 114.99999999999999111821580299875...
You can read a more detailed analysis of how .1 is represented in Python in: http://docs.python.org/tutorial/floatingpoint.html http://docs.python.org/tutorial/floatingpoint.html