- 舍弃小数部分
>>> math.trunc(12.533222)
12
>>> round(12.2544)
12
也可以:
int(12.0)=12
- 按给定小数位数四舍五入
>>> round(12.2544, 3)
12.254
- 向上取整
>>> math.ceil(12.4584)
13
- 向下取整
>>> math.floor(12.4584)
12
>>> math.trunc(12.533222)
12
>>> round(12.2544)
12
也可以:
int(12.0)=12
>>> round(12.2544, 3)
12.254
>>> math.ceil(12.4584)
13
>>> math.floor(12.4584)
12
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。