向上向下取整、四舍五入取整
import math
# 向上取整
math.ceil(2.3)
3
math.ceil(2.6)
3
# 向下取整
math.floor(2.3)
2
math.floor(2.6)
2
# 四舍五入
round(2.3)
2
round(2.6)
3
# 返回值都是整型
a = math.ceil(2.3)
type(a)
# <class 'int'>
b = math.floor(2.3)
type(b)
# <class 'int'>
import math
# 向上取整
math.ceil(2.3)
3
math.ceil(2.6)
3
# 向下取整
math.floor(2.3)
2
math.floor(2.6)
2
# 四舍五入
round(2.3)
2
round(2.6)
3
# 返回值都是整型
a = math.ceil(2.3)
type(a)
# <class 'int'>
b = math.floor(2.3)
type(b)
# <class 'int'>
本文标题:Python模块---向上向下取整、四舍五入取整
本文链接:https://www.haomeiwen.com/subject/iehqeqtx.html
网友评论