Which is the deeper truth? Don't use..
You check your local applicable law to see what rounding mode you need to apply, and apply that to get back to full cents.
-
-
Note that actually knowing the fractional part (up to a certain precision) allows you to apply the correct rounding mode, unlike what happens when calculating using integers, where truncation always happens.
-
In my experience, "use floating-point, manage the bookkeeping yourself, and pray you don't get unlucky with error propagation" is much more prone to errors than "use a decimal type".
-
Until you hit an integer overflow, and things go belly up in pretty dramatic ways.
-
But my entire point here is that using floats is perfectly fine for money, if you follow a small number of rules, whereas using regexes for HTML parsing is bound to fail due to HTML being a recursive language, and regexes recognizing regular languages.
-
I think that's fair. My point is that it's not necessarily obvious you're getting burned by FPEP until you're in deep, whereas it's usually clear if a regex isn't returning what you think it should. A lot of F500s have lost a lot of money to very silly FP errors!
-
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.
- 3 more replies
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.