只得到 1 个小数位

只得到 1 个小数位

问题描述:

如何将 45.34531 转换为 45.3?

你想用一个数字来表示吗:

Are you trying to represent it with only one digit:

print("{:.1f}".format(number)) # Python3
print "%.1f" % number          # Python2

或者实际上四舍五入其他小数位?

or actually round off the other decimal places?

round(number,1)

甚至严格四舍五入?

math.floor(number*10)/10