Python is DOOMED! Again!
steve+comp.lang.python at pearwood.info
Tue Jan 27 01:22:39 CET 2015
> how do you represent a raise of 10% exactly if
> not with binary floating point?
In Python today, the best solution is probably to use Decimals:
from decimal import Decimal
raise = Decimal("0.1")
But the traditional solution is to track money in cents, or a fixed fraction
of a cent, using integers, and do everything in integer maths. That has the
disadvantage that division always truncates, but if you care about that you
can easily write your own division-with-round-to-nearest function.
Or use Decimal, which handles rounding correctly and flexibly.
More information about the Python-list