# Python v2.7- "%.15g" % f # Python v3.0 format(f, ".15g") # Python 2.7+, 3.2+ # Pass float to Decimal constructor from decimal import Decimal Decimal(f)