Python, databases, floating point, and money

klaatu at evertek.net klaatu at evertek.net
Fri Dec 6 16:28:57 EST 2002


What is the accepted method of dealing with monetary calculations and
databases, specifically in Python, but also in general?  I know that
there are floating point types, but it seems to me that their
imprecision would cause significant problems when dealing with monetary
quantities, once those numbers get very large at all.

One scheme I've thought of is to use two fields - an integer (probably
64bit, internally represented as a Python long) representing the
quantity, and then another integer field that has the number of places
to the right of the zero (i.e., the power of 10 to divide by to get the
true number).  But it seems like this would be horribly non-standard.

How do existing applications cope with this?

Thanks,
Michael



More information about the Python-list mailing list