Float Sum Broken?
print(0.1 + 0.2 == 0.3) returns False Why?
Solution 1:
It's not broken, that's how floating point arithmetic works.
Is floating point math broken?
I recommend reading this http://blog.reverberate.org/2014/09/what-every-computer-programmer-should.html
Solution 2:
It's a floating point precision issue. Basically floats cannot all be represented accurately in binary (and thus the underlying functions are working with imprecise representations of the numbers that you intend to use). Try using decimal.Decimal.
from decimal import Decimal
print Decimal('0.1') + Decimal('0.2')
Post a Comment for "Float Sum Broken?"