Created
October 4, 2011 20:57
-
-
Save tkaemming/1262787 to your computer and use it in GitHub Desktop.
decimal behavior when casting floats in python 2.6 and 2.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tkaemming@reventon % python2.6 ~ | |
Python 2.6.6 (r266:84292, Jun 16 2011, 16:59:16) | |
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from decimal import Decimal | |
>>> Decimal(15.0/100.0) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/System/Library/Frameworks/Python.framework/Versions/2.6/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tkaemming@reventon % python ~ | |
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) | |
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from decimal import Decimal | |
>>> Decimal(15.0/100.0) | |
Decimal('0.1499999999999999944488848768742172978818416595458984375') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment