How about adding rational fraction to Python?

Jorge Godoy jgodoy at
Mon Feb 25 11:59:31 CET 2008

Paul Rubin wrote:

> Carl Banks <pavlovevidence at> writes:
>> Try doing numerical integration sometime with rationals, and tell me
>> how that works out.  Try calculating compound interest and storing
>> results for 1000 customers every month, and compare the size of your
>> database before and after.
> Usually you would round to the nearest penny before storing in the
> database.

There are cases where the law requires a higher precision or where the
rounding has to be a floor or...

Some things make no sense and when dealing with money things make even less
sense to either protect the customer or to grant the State getting its
share of the transaction.

Here in Brasil, for example, gas stations have to display the price with 3
decimal digits and round the end result down (IIRC).  A truck filling 117
liters at 1.239 reais per liter starts making a mess...  If the owner wants
to track "losses" due to rounding or if he wants to make his inventory of
fuel accurately, he won't be able to save just what he billed the customer
otherwise things won't match by the end of the month.

More information about the Python-list mailing list