4 ms·
I try to avoid using floats when doing business calculations. Base 2 doesn't work well with our base 10 currency. Real world example: 1.09 - 1.09375 Double: 0
by yodacola 9y ago
I try to avoid using floats when doing business calculations. Base 2 doesn't work well with our base 10 currency.
Real world example: 1.09 - 1.09375
Double: 0.00374999999999992
Decimal: 0.00375
- wruza 9y agoBase 2 doesn’t work well with military too: http://www-users.math.umn.edu/~arnold/disasters/patriot.html http://www-users.math.umn.edu/~arnold/disasters/patriot.html
- lucio 9y agoAn easier example: type this in your browser console: 0.1 + 0.2 == 0.3 false!(?)
- evincarofautumn 9y agoDoing calculations with an exact number type such as [big] rationals, and then explicitly converting to floating point or rounding/truncating digits of precision as needed, is a pretty good middle ground for many applications. 109/100 − 109375/100000 = 109/100 − 35/32 = −3/800 = −3.75ᴇ−3.