Adding Floating-Point Decimals for Fun and Profit

·Hacker News··

Many people know that you shouldn’t do decimal calculations, such as those involving U.S. dollars and cents, with the floating-point numbers in most programming languages. This is because decimal numbers can’t be expressed exactly as such floating-point numbers, so you will encounter rounding errors. Famously, with IEEE double-precision floats, 0.1 + 0.2 is not 0.3, but rather, 0.30000000000000004. On the other hand, I use a Python REPL to add up decimal numbers for receipts all the time. Of

Read full article →

Related Articles

Singapore govt dating app uses Gale-Shapley stable marriage algorithm
rzk · Hacker News · 1d ago
The top secret URSALA, RAQUEL, and FARRAH satellites (2025)
Bluestein · Hacker News · 14h ago
Livenerf: Has Opus 5.5 been nerfed yet?
bryan0 · Hacker News · 1d ago
EDG C++ front-end goes public
iandinwoodie · Hacker News · 17h ago
A brief history of the Bloomberg terminal
rbanffy · Hacker News · 21h ago