Live data from Hacker News

The Right Way to Compare Floats in Python

davidamos.dev

1–2 of 2 posts

Re: The Right Way to Compare Floats in Python

#2
Not 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.