Hacker News new | past | comments | ask | show | jobs | submit login

The whole point is to support the kind of accounting that happens in real business, which does not do things with rational numbers. One third of your bill does not charge you one third of a penny, these aren't rational numbers but the operations on them involve rounding.



Dec64 does not reflect what happens in real business any more than IEEE floats does. "There is no reals" applies to currency too, but in a stronger form: in currency there are no fractions either. Translation: in real life, no one can give you a fraction of a cent. So the programmer has to make a decision about what happens to those fractions when you give 1/3 off.

Every newbie programmer tries to avoid thing about this by using IEEE floats. They discover, usually years later after some anal auditor has come down on them like a ton of bricks for the hundredth time because the dropped low order bits from 1/3 of a cent hit that 1 in a billion case and effected a significant digit, and then it finally dawns that 1 in a billion isn't really 1 in a billion because thousands of such calculations get combined into a single profit and loss figure that is out by 2 cents and chasing that 2 cents for 2 weeks really only to discover it was caused by a computer can't compute, really, really pisses off the auditor, that you realise if aren't thinking about those fractions of a cent as hard as a C programmer focuses on malloc(), they will have gone to whoop whoop in half the code you have written. You will have nightmares about divide signs for the rest of your life. Crockford seems to think Dec64 allows the programmer to avoid thinking about the problem. He is just as wrong as every newbie programmer.

There is only one safe format for currency that accurately reflects this reality, that forces you to accept that you must think about those fractions of a cent. It is the humble integer. You put in it the lowest denomination: cents in the case of the USA. And then when you write total = subtotal / 3 * 4, and you test it, your error stands out like dogs balls, and you fix it.




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

Search: