TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Right Way to Compare Floats in Python

3 pointsby da12about 3 years ago

1 comment

jqpabc123about 3 years ago
Not unique or limited to Python.<p>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.<p>In many cases, scaled integers are a better alternative. For example, when dealing with money&#x2F;dollars, work with pennies and convert to dollars and cents for display using a simple division&#x2F;modulus function.