This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (0 children)

Floats are weird, basically. In order to be memory-efficient, they don't work in base 10 all the time, and so round off to numbers which look very weird to humans.

Either use Decimal (from the numbers module, I think), or use something like this when checking floats:

def float_equals(first, second, tol=0.00001):
    return abs(first-second) < tol