Decimal vs float

Kay Schluehr kay.schluehr at
Thu Jan 19 11:36:51 CET 2006

I wonder why this expression works:

>>> decimal.Decimal("5.5")**1024

but this one causes an error


Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
OverflowError: (34, 'Result too large')

Another quirk is the follwoing:

>>> decimal.Decimal(5.5)
Traceback (most recent call last):
TypeError: Cannot convert float to Decimal.  First convert the float to
a string

If Mr. interpreter is as slick as he is why doesn't he convert the
float by himself? This is at most a warning caused by possible rounding
errors of float.

Instead of dealing with awkward wrappers, I wonder if literals
currently interpreted as floats could not be interpreted as Decimal
objects in future?


More information about the Python-list mailing list