Why not FP for Money?

Paul Rubin http
Tue Sep 21 14:56:30 EDT 2004


Barkmann at gmail.com (Chris Barker) writes:
> 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.

Yes, "correctly" means "exactly the way decimal arithmetic does it,
and if your answer is different in the slightest, the auditors are
all over your ass".

> If you were to use FP, you could have your IEEE 754 hardware do the
> rounding for you

But you'll get different answers than decimal arithmetic would give
you, so the auditors will be all over your ass if you do it that way.
You don't want that.  You need decimal arithmetic.

> and get better performance to boot. 

This is one situation where really, nobody cares about performance.
Accounting programs simply don't spend any significant fraction of
their CPU time doing arithmetic on money amounts.  It's all I/O,
database lookups, etc.



More information about the Python-list mailing list