Python <2.7
"%.15g" % f
或在Python 3.0中:
format(f, ".15g")
Python 2.7 +,3.2 +
只需将float
Decimal直接传递给构造函数,如下所示:
from decimal import DecimalDecimal(f)

"%.15g" % f
或在Python 3.0中:
format(f, ".15g")
只需将float
Decimal直接传递给构造函数,如下所示:
from decimal import DecimalDecimal(f)