Which is the deeper truth? Don't use..
-
-
How much do you owe on a $1 transaction with 4.9% sales tax? Under this scheme, you'd represent this as 100¢ × 104.9%, which gets you a value that is close to but not equal to 104.9.pic.twitter.com/6yTcN8s7Zm
-
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.
- 5 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.