Python <2.7
"%.15g" % f
Or in Python 3.0:
format(f, ".15g")
Python 2.7+, 3.2+
Just pass the float to Decimal
constructor directly, like this:
from decimal import Decimal
Decimal(f)
"%.15g" % f
Or in Python 3.0:
format(f, ".15g")
Just pass the float to Decimal
constructor directly, like this:
from decimal import Decimal
Decimal(f)