Thursday, November 17, 2011

Decimal fun in Python 2.6 & 2.7

In Python 2.6:

$ python2.6
Python 2.6.7 (r267:88850, Jul 10 2011, 09:55:27)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = float(1.0)
>>> import decimal
>>> decimal.Decimal(f)
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.6/decimal.py", line 649, in __new__
"First convert the float to a string")
TypeError: Cannot convert float to Decimal. First convert the float to a string
>>>

Upgraded to Python 2.7:

$ python2.7
Python 2.7.2+ (default, Aug 16 2011, 07:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = float(1.0)
>>> import decimal
>>> decimal.Decimal(f)
Decimal('1')
>>>

1 comment:

fUaOmoYcbGsV said...

Super Lucky Casino has 빅카지노 selection of|quite so much of|a wide selection of} casino fashion video games that you just can} play. They have more than half a dozen slots video games which are be} themed in varied ways. Each game has properly over a dozen machines select from|to choose from} together with varied every day prizes. A few of them even include match modes and leaderboards to see how you stack up towards the competition. Pharaoh’s Way Slots certainly one of the|is amongst the|is doubtless considered one of the} hottest slots video games out there. The developer boasts that over ten trillion video games have been played.