如何将 45.34531转换为 45.3?
45.34531
45.3
你是想用一个数字来表示它吗:
print("{:.1f}".format(number)) # Python3 print "%.1f" % number # Python2
还是四舍五入?
round(number,1)
甚至是严格向下舍入?
math.floor(number*10)/10
round(number, 1)
>>> "{:.1f}".format(45.34531) '45.3'
或者使用内置的圆形:
>>> round(45.34531, 1) 45.299999999999997