Why not FP for Money?

Chris Barker Barkmann at gmail.com
Tue Sep 21 03:25:25 EDT 2004


Hi all,

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:

http://www-2.cs.cmu.edu/~quake-papers/robust-arithmetic.abstract

-Chris



More information about the Python-list mailing list