数据取整一般有三种模式:向下取整、向上取整和四舍五入
- 向下取整常用 int() 和 math.floor()两方法
In [1]: int(3.9)
Out[1]: 3
In [2]: int(2.1)
Out[2]: 2
In [3]:import math
math.floor(3.9)
Out[3]: 3
- 向下取整常用 math.ceil()方法
In [4]: math.ceil(5.3)
Out[4]: 6
- 向下取整常用 round() 方法 (0.5 舍 0.51入)
In [5]: round(4.5)
Out[5]: 4
In [6]: round(4.51)
Out[6]: 5