Decimal arithmatic, was Re: Python GUI app to impress the boss?
phr-n2002b at NOSPAMnightsong.com
Mon Sep 30 00:42:21 EDT 2002
"Chris Gonnerman" <chris.gonnerman at newcenturycomputers.net> writes:
> > What do you mean by "right"? What do you mean by "all
> > cases"?
> The original subject is *business* arithmetic. There is no
> choice but to use decimal arithmetic if you want your math
> results to match good-old-fashioned pen and paper math.
No, I'm still not convinced. Is business arithmetic well-defined
enough that you can never do the same calculation two ways and get
Example: bunches are three for a dollar. How much do you pay if you
buy nine bananas?
price_per_banana = 1.00 / 3
number_of_bananas = 9
total_price = number_of_bananas * price_per_banana
price_per_bunch = 1.00 # three bananas
number_of_bunches = 3
total_price = number_of_bunches * price_per_banana
With floating point and rounding on output, you get the same answer
With decimal arithmetic, you get $2.97 the first way and $3.00 the
For "business arithmetic" to always give the same answer, it has to
forbid at least one of those methods of doing the problem.
More information about the Python-list