python取整函数 向上取整 向下取整 四舍五入

向上取整

>>> import math
>>> math.ceil(3.5)
4
>>> math.ceil(3.4)
4
>>> 

向下取整

>>> math.floor(3.4)
3
>>> 

四舍五入

>>> round(3.4)
3
>>> round(3.5)
4
>>> 

取整部分

>>> math.trunc(3.5)
3
>>> 

 

posted @ 2020-04-16 15:56  pple  阅读(3194)  评论(0编辑  收藏  举报
以终为始,你期待的那天不会太遥远。