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

Paul Rubin phr-n2002b at NOSPAMnightsong.com
Mon Sep 30 08:36:50 CEST 2002


"Chris Gonnerman" <chris.gonnerman at newcenturycomputers.net> writes:
> > With decimal arithmetic, you get $2.97 the first way and
> > $3.00 the second way.
> 
> Excellent example, wrong focus.  The business user (in this
> case, the retail store owner/manager) would define which
> method, and which results, are right.  The second mode is
> the "canonical" way in the manual system, but lately I've
> realized that many (most?) retail POS systems can do it "both"
> ways, handling single items by a variation of method 1 which gives answers
> consistent with method 2.
> 
> I'm glad I didn't have to write and debug that code.

I'm really skeptical that any "business user" can specify a set of
rules that gets all this stuff straight for a complex business
involving cents-off coupons, percentage advertising discounts, etc.
It sounds much more complicated than what we usually call software
implementation, and it sounds like it has to be done differently for
every business situation.  They're almost certainly better off using
some method that gives consistent results at the end.

I worked on one business application where the vendor felt that any
floating point roundoff errors were unacceptable.  He had me implement
exact rational arithmetic (easy in Python using the gmpy package).
All intermediate results were represented as exact integer ratios, so
you were guaranteed that 3 * (1/3) == 1.  This was not the same as
decimal arithmetic.  You would never get $2.97 as an answer for the
banana problem.  But I don't think any customers complained.



More information about the Python-list mailing list