Python, databases, floating point, and money

Dan Bishop danb_83 at yahoo.com
Sat Dec 7 04:12:17 EST 2002


<klaatu at evertek.net> wrote in message news:<asr4qp$3gc$1 at ins22.netins.net>...
> 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?

At the financial institution I used to work for, we simply stored
monetary amounts as cents instead of dollars (e.g., $99.88 is stored
as the integer 9988.)



More information about the Python-list mailing list