Decimal arithmatic, was Re: Python GUI app to impress the boss?

Stuart D. Gathman stuart at bmsi.com
Mon Sep 23 17:16:10 EDT 2002


On Sat, 21 Sep 2002 23:10:09 -0400, Christian Tismer wrote:

> Dan Bishop wrote:

>  > Please name one other real-world situation in which decimal
>  > arithmetic is actually *needed*.
> 
> There is no reason to argue about that. Decimal arithmetic is exact for
> most of the operations bankers require. They have been demanding for it
> since decades, and they will not drop it. 

Let me add a horror story of what happens when financial
applications do *not* demand fixed point/decimal arithmetic.

We took on a client whose accounting system used binary floats for all
dollar amounts.  And I mean *dollar* amounts, not penney amounts.  Since
all pennies were approximate, the total due at the bottom of the invoices
would rarely match what the customer would get adding up the line items
on a calculator.  It was only off by a few cents, but it tended to make
customers lose faith in the system.  Statements also did not add up, and
the Balance Sheet didn't balance.

We converted their system to use fixed point, and now everything balances
and totals to the penney.  Unfortunately, their CPA keeps his own version
of their General Ledger on Excel with binary floating point.  The CPA
balance sheets do not balance.  The CPA General Journal transactions do
not balance.  I demonstrated with a calculator that the CPA figures did
not balance, but they insisted that we had to go with the CPA figures
because he is a CPA, and I'm just a programmer.
This is tricky since their new General ledger does not accept unbalanced
transactions.

My solution was to create a 'CPA adjustment' account to contain
all the discrepancies, and manually decide how to allocate the
extra/missing pennies for the CPA transactions.

There ought to be severe penalties for idiots that use floating point
dollars for financial applications.  If forced to use floating point
(e.g. because customer demands BASIC), then keep money amounts in
whole pennies (or whatever the smallest currency unit for the country
is), and divide by 100 (or whatever) for printing only (or just add the
decimal point yourself).

-- 
Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - Mozart background
song for the Microsoft "Where do you want to go from here?" commercial.



More information about the Python-list mailing list