What is the best way to compare floats for almost-equality in Python?

It’s well known that comparing floats for equality is a little fiddly due to rounding and precision issues.

For example:
https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

What is the recommended way to deal with this in Python?

Surely there is a standard library function for this somewhere?

17 Answers
17

Leave a Comment