Created
August 24, 2011 08:53
-
-
Save fredj/1167619 to your computer and use it in GitHub Desktop.
use decimal to convert string to float
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
from decimal import * | |
if 'x' in request.params: | |
# deactivate all traps | |
getcontext().traps = {} | |
x = Decimal(request.params['x']) | |
if x.is_infinite() or x.is_nan(): | |
# x is NaN, -Infinity or +Infinity | |
pass | |
else: | |
# x should be a valid float | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment