在Python中,可以使用math模块中的floor函数来实现向下取整。以下是示例代码: python import math # 示例数值 num1 = 2.3 num2 = -2.3 # 向下取整 result1 = math.floor(num1) result2 = math.floor(num2) print(f"{num1} 向下取整为 {result1}") # 输出: 2.3 向下取整为 2 print(f"{num2} 向下...
向上取整 使用ceil(): import math x = 0.55 x0 = math.ceil(x) 1. 2. 3. 4. 向下取整 使用floor(): import math x = 0.55 x1 = math.floor(x) 1. 2. 3. 4. 如下: