Skip to content

Instantly share code, notes, and snippets.

@fredj
Created August 24, 2011 08:53
Show Gist options
  • Save fredj/1167619 to your computer and use it in GitHub Desktop.
Save fredj/1167619 to your computer and use it in GitHub Desktop.
use decimal to convert string to float
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