python 向上取整和向下取整

发布时间 2023-08-08 00:10:29作者: 莫大师兄

math 模块

math.ceil() 向上取整

math.floor() 向下取整

 

 

# 导入 math 包
import math

# 输出向下舍入到最接近的整数
print(math.floor(0.6))
print(math.floor(1.4))
print(math.floor(5.3))
print(math.floor(-5.3))
print(math.floor(22.6))
print(math.floor(10.0))