Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The rounding behavior with true decimals is easy to control and understand across number magnitudes and doesn't suffer from platform specific quirks like floats/doubles.

The article's images clearly show the rounding error mess your get without decimals.

 help



There's still catastrophic cancellation, where subtracting two large numbers that are very close results in an answer with reduced precision.

But the rounding errors are way down in the nano-cents. Not worrying about them is cheaper!

The decimal library worries about rounding, that's basically free. With floats you need to decide when to use rounding (because you don't want to show a balance of -0.000000086) and it's more difficult to use automatic checks for the same reason.

If you're calculating your monthly expenses that's okay, but across millions of transactions of arbitrary amounts, something financial systems do regularly, aggregates start not adding up and you don't know where the money went.



Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: