Why not FP for Money?

Christopher A. Craig com-nospam at ccraig.org
Thu Sep 23 14:56:00 CEST 2004

Barkmann at gmail.com (Chris Barker) writes:

> """
> consider, for 
> example, a program that calculates payments on a real estate mortgage.
> Given that interest may need to be calculated on a daily basis, and
> that
> the daily interest rate is a very small fraction, the imprecision of 
> floating point can then become much more significant relative to the 
> desired quantity.  And given that there's a *lot* of calculations over
> which this imprecision can build (a 30-year mortgage ~= 10957 days),
> and
> the exponential nature of the interest calculation, this can become a 
> real issue.
> """
> OK, so how the heck do you do that? Any system, fixed or FP, binary or
> decimal, is going to have the same issue. I think the answer is that
> you have to round, but you can follow the appropriate accounting
> practice when you do so.

You could use a rational, but you'ld get some heinously slow
calculations (and you'ld need all integer exponents since a fractional
exponent could get you an irrational result).

Christopher A. Craig <com-nospam at ccraig.org>
"There is no subject, however complex, which--if studied with patience
and intelligence--will not become more complex." New Speaker's Handbook

More information about the Python-list mailing list