3 ms·
> It's an amazingly pervasive myth taught in CS 101 courses that "you should never use floating point types for currencies, or you might go to jail". In reality
by throwaway613834 9y ago
> It's an amazingly pervasive myth taught in CS 101 courses that "you should never use floating point types for currencies, or you might go to jail". In reality floats are fine for most financial applications, and for almost all those that would find themselves in a spreadsheet.
What do you think about this then? https://www.journalofaccountancy.com/issues/2014/mar/excel-calculation-errors.html https://www.journalofaccountancy.com/issues/2014/mar/excel-c...
- dmurray 9y agoI think that if anyone ever needs to give me 12 quadrillion dollars (more than a million dollars for every human alive), they can keep the extra 21 dollars. I'm not unfamiliar with the idea that floating point numbers have a limited precision, I'm saying the precision is normally good enough.
- throwaway613834 9y ago> I think that if anyone ever needs to give me 12 quadrillion dollars (more than a billion dollars for every human alive), they can keep the extra 21 dollars. You're missing the point. You don't need a 1-cent error for a smaller error to throw things off. Say someone owes you $0.30 and pays you $0.10 and $0.20. If the data type inherently has 2 digits past the decimal, or if you just do everything with integers, then they'll be debt-free by the end and nothing will go wrong. But if you're representing these with binary floats, then you have to remember to explicitly do rounding at precisely the correct intermediate spots in order to avoid incorrectly listing them as still having a balance. Even for a programmer it's too easy to either put it or forget to put it in the correct spot, let alone for a non-programmer writing the sheet. And that's just one example. I'm sure there are tons more I can't think of off the top of my head. It's not like people made the decimal data types for nothing.