Fredrik Lundh wrote:
>>>>str(1.1)
> 
> '1.1'
> 
>>>>repr(1.1)
> 
> '1.1000000000000001'

To add to the confusion:

 >>> str(1.1000000000000001)
'1.1'
 >>> repr(1.1000000000000001)
'1.1000000000000001'

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))
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to