a = float(10/3.0)
print round(a,2) #first
print "%.2f" % (a) #second
from decimal import Decimal#third
print Decimal(a).quantize(Decimal('0.00'))
python 保留两位小数
最新推荐文章于 2025-05-19 11:40:11 发布
a = float(10/3.0)
print round(a,2) #first
print "%.2f" % (a) #second
from decimal import Decimal#third
print Decimal(a).quantize(Decimal('0.00'))