Decimal vs float
Kay Schluehr
kay.schluehr at gmx.net
Thu Jan 19 05:36:51 EST 2006
I wonder why this expression works:
>>> decimal.Decimal("5.5")**1024
Decimal("1.353299876254915295189966576E+758")
but this one causes an error
5.5**1024
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?
Kay
More information about the Python-list
mailing list