Decimal vs float
lycka at carmen.se
Thu Jan 19 12:17:24 EST 2006
Fredrik Lundh wrote:
To add to the confusion:
Floating point numbers are not precise.
Decimals are, so they require precise
information when they are constructed.
If you want to use the rounding that str()
uses when you create a Decimal instance,
please use that. Decimal(str(x)). By forcing
you to do that, Python makes you aware of the
problem and you can avoid nasty surprices.
If you think that's excessive typing, just
define a simple function.
def D(x): return Decimal(str(x))
More information about the Python-list