1.round(x,a)
当规定保留位数<小数点后两位且a写出时,结果总是保留小数点后一位(慎用!)
单纯的round(x)是精确到个位,结果为整数
可精确到个位、十位及以上
>>>print(round(12.678,2))
12.68
>>> print(round(12.678,1))
12.7
>>> print(round(12.678,0))
13.0
>>> print(round(12.678))
13
>>> print(round(12.678,-1))
10.0
>>> print(round(12.678,-2))
0.0
2.format()
结果保留小数严格遵照指令
最多可精确到个位,十位及以上报错
>>> print('{:.2f}'.format(12.678))
12.68
>>> print('{:.1f}'.format(12.678))
12.7
>>> print('{:.0f}'.format(12.678))
13
>>> print('{:.-1f}'.format(12.678))
报错
3.int()
抹去小数(不是四舍五入,直接抹去)
>>> int(12.678)
12
4.math.floor() math.ceil()
>>> import math
>>> math.floor(12.678)
12
>>> math.ceil(12.678)
13