Why not FP for Money?
Barkmann at gmail.com
Tue Sep 21 09:25:25 CEST 2004
I promise this is not a troll... Really, it's embarassing, because
this is one Engineer that DID take a Numerical Analysis course, and
from William Kahan, no less, and I still don't really get it. (and
yes, Alex, I could have gotten my degree without it)
I've seen it suggested various times that one should use fixed point
for money, perhaps micro cents represented as integers. However, if
you do that, you need to make sure you do all the rounding correctly.
If you were to use FP, you could have your IEEE 754 hardware do the
rounding for you, and get better performance to boot. If you are
rounding to cents at the end anyway, I can't see that the errors you'd
get with 64 bit FP numbers would ever be an issue.
I understand that when your numbers got large enough, you'd start to
lose the pennies, but how many of us have the luxury of doing
computation with quadrillions of dollars actually care about the
pennies? Besides, you could check for HUGE numbers and do something
special with them if you wanted.
What am I missing here?
By the way has anyone done anything with "Adaptive Precision
Floating-Point Arithmetic" ? It looks pretty handy:
More information about the Python-list