Decimal arithmatic, was Re: Python GUI app to impress the boss?
Paul Rubin
phr-n2002b at NOSPAMnightsong.com
Sun Sep 29 19:14:20 EDT 2002
"Chris Gonnerman" <chris.gonnerman at newcenturycomputers.net> writes:
> >>> .70 * .05
> 0.034999999999999996
>
> Rounded to two decimals, that's 0.03; but done in proper
> decimal numbers, the answer should be 0.035, rounded to 0.04
> using either "classic" or "banker's" decimal rounding.
> ...
> So, Bengt, how do I do this right using only floats? I can't.
> I have to have decimal arithmetic to get the right answer.
How about just adding a small amount before rounding at the end?
>>> (.70 * .05) + .000000001
rounds to the right thing.
More information about the Python-list
mailing list