Floats for money are fine, if done right (use cent as the base value, i.e., store $0.01 as 1.0e0). You get 53 bits of precision, and graceful overflow behaviour.
I've never heard of any such case. Even if you use floats incorrectly, the accumulated error tends to be small.
-
-
In financial calculations, it's common to iterate over a large number of periods (e.g., mortgages, bond payments, and so on) or a large number of transactions (e.g., all the payroll checks). Adding or subtracting iteratively easily leads to catastrophic cancellations with FPs.
-
For such calculations, when you store back to an integer in every step, you accumulate a much bigger error in total. I don't see how floats would hurt you there in a worse way.
-
The alternative is not "use integers"; it's "use the right tool for the job, which is usually your language's Money or BigDecimal type".
-
If your language has such a thing, this is sane advice.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.