The Right Way to Compare Floats in Python
davidamos.dev
The Right Way to Compare Floats in Python
1–2 of 2 posts
Re: The Right Way to Compare Floats in Python
#2Not unique or limited to Python.
Floats (fractions and decimals) are only approximations. It is not possible to represent some of them with complete accuracy within the limits of finite binary storage.
In many cases, scaled integers are a better alternative. For example, when dealing with money/dollars, work with pennies and convert to dollars and cents for display using a simple division/modulus function.