Numeric data question

Terry Reedy tjreedy at udel.edu
Wed Jul 24 19:11:05 EDT 2002


"terry" <tg5027 at citlink.net> wrote in message
news:mailman.1027526808.16869.python-list at python.org...
>
> >>  Well, PostgreSQL does have a money type, but IIRC it's just a
> >> float with a fixed number of decimal places. You could just
> >> use pennies as the unit and integer math though.

> Thanks Tim, it is a more complex representation than just float
> as it also contains the decimal places.  I haven't seen the exact
> internal format in Postgres, but it's a very common datatype in
> many databases.  In general it's not appropriate/legal to use
> integer or floating point math when dealing with money.  It
> creates too many coding dependent variations in results - not to
> mention maintenance nightmares.

If the amounts of money you are dealing with are well less than the
max, and if you are only doing + and - (accounting in the strict
sense) and maybe * by int amounts, ints using the lowest denomination
(cents in the US) work just fine.  +/- 2 billion cents is +/- 20
million dollars.  Python's integration of longs with ints should
remove the upper limit constraint.  Financial calcs with interest and
other rates requires more care.

TJR






More information about the Python-list mailing list