I'm doing a simple addition "11111.66+1111.38+60000" using python. Why python gives me "72223.04000000001" rather than "72223.04"?
I've tried python2.7.12/Python3.5.2 in Linux and Python3.7.2 in Windows.
11111.66+1111.38+60000
I'm doing a simple addition "11111.66+1111.38+60000" using python. Why python gives me "72223.04000000001" rather than "72223.04"?
I've tried python2.7.12/Python3.5.2 in Linux and Python3.7.2 in Windows.
11111.66+1111.38+60000
This is a run-of-the-mill floating point coding issue, it's not an error. It just reflects the way numbers are represented in the belly of the machine.
Try this:
from decimal import Decimal
float(Decimal(11111.66)+Decimal(1111.38)+Decimal(60000))
Where the decimal library irons out these little squiggles.
More here: https://docs.python.org/2/tutorial/floatingpoint.html