Why not FP for Money?
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Wed Sep 22 13:08:21 EDT 2004
On Wed, 22 Sep 2004 18:35:44 +0200, rumours say that aleaxit at yahoo.com
(Alex Martelli) might have written:
>> Run it with Python 2.4. See what goes wrong? Put the numbers in an
>> Excel sheet too.
>
>The problem is pretty clear, but it shows up with decimal just as well
>as with float: each of 'amount' and 'vat' (in Euro) has a fraction of a
>eurocent that is less than 0.5 (about 0.4 eurocents each), and you don't
>round them to eurocents before summing, so the total ends up with a
>fraction of a eurocent that is _more_ than 0.5. So the final numbers
>show, identically badly with both decimals and floats:
Oops! yes, this shows my inexperience with the decimal type; in my
session, the results were correct since I had earlier issued (after
trial and error) a
decimal.getcontext().prec=6
which I didn't include my post (forgetting about its importance).
Hence, you are correct saying that my confidence in the Decimal type
should not be absolute.
--
TZOTZIOY, I speak England very best,
"Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek
More information about the Python-list
mailing list