[Tutor] Decimal fixed point representation

Bill Campbell bill at celestial.net
Fri Nov 21 19:23:14 CET 2008

On Fri, Nov 21, 2008, Dinesh B Vadhia wrote:
>   That's right, it is the Decimal module I'm trying to understand.  And,
>   it is how to represent a decimal floating point number as a
>   common/vulgar fraction eg 1.234 = 1234/1000.  How do you do this using
>   the Decimal module?  The motivation is to avoid floating point
>   calculations and use integers only (don't ask why!).  Cheers!

I can understand why if one is writing accounting applications that have to
be accurate to the penny (or whatever in the local currency).  Accountants
and auditors don't like rounding errors.

The accounting system I wrote in the mid-80s, and still use today, is
written mostly in C, and handles all monitary calculations in cents in long
integers with appropriate input and output routines to make them look to
the world as it would expect.

There was (is?) a FixedPoint package in python that I use for handling
dollar amounts.  It came out before the Decimal type, and I am not fixing
something that works.

The only machines I worked on extensively that handled decimal arithmatic
very well were the Burroughs Medium Systems B-2500 through B-4800 which did
everything in decimal which made a lot of sense since they were designed
primarily to run COBOL accounting applications.

INTERNET:   bill at celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:          (206) 236-1676  Mercer Island, WA 98040-0820
Fax:            (206) 232-9186

Scientists are explorers. Philosophers are tourists. -- Richard Feynman

More information about the Tutor mailing list