Numeric data question

James J. Besemer jb at cascade-sys.com
Thu Jul 25 15:57:47 EDT 2002


Terry Reedy wrote:

> "terry" <tg5027 at citlink.net> wrote in message
> > 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,

Accounting per se cannot be limited to the above operations.  Think of
tax tables, withholding percentages, asset depreciation, interest
calculations, etc., etc.

"Accounting" generally is far from trivial and is way more complicated
than balancing your checkbook.

> 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.

Note that "currency" is more than just dollars and cents.  First off,
even in US currency there is need to talk about fractions of a penny.
E.g., in the stock market, 1/8 "point" is $0.125.  Also you quickly run
into scale problems with non-US currencies, e.g., 2 billion Lira is too
harsh an upper limit.  (My last hotel bill in Venice was over L
1.000.000).

FWIW, Microsoft COM defines a currency type as an 8-byte, two's
complement integer, scaled by 10,000.  This is the format VB uses.  This
gives a fixed point decimal value with 15 digits of whole number and 4
digits of fraction.  A lot of databases allow the designer to explicitly
specify field size and precision to better control the trade-off of value
range vs. space consumed.

Luckily nobody I know of still uses a non-decimal currency, like the old
English system.  Lesse, 5 shillings to the crown, 4 crowns to the pound,
2 shillings per florin, two sixpence (12 pennies) per shilling, two
tuppence per groat, two pennies per tuppence, 2 farthings to the
ha'penny, and they actually minted coins as small as 1/4 farthing.
Basically 12 pennies to the shilling, and 20 shillings to the pound, or
240 pennies per pound.  THAT was when money was worth something, when you
minted coins worth 1/16 of a cent or 1/3840th of your basic monetary
unit!

Regards

--jb

--
James J. Besemer  503-280-0838 voice
http://cascade-sys.com  503-280-0375 fax
mailto:jb at cascade-sys.com






More information about the Python-list mailing list