# Python 向下取整示例代码
# 使用 math 模块中的 floor 函数
import math
# 定义一个浮点数
num = 4.7
# 向下取整
floor_result = math.floor(num)
print(f"原始数值: {num}")
print(f"向下取整后的结果: {floor_result}")
# 如果是负数的情况
negative_num = -3.2
negative_floor_result = math.floor(negative_num)
print(f"原始负数值: {negative_num}")
print(f"向下取整后的结果: {negative_floor_result}")
math.floor() 函数用于对给定的数值进行向下取整操作。无论数值是正数还是负数,它都会返回不大于该数值的最大整数。math.floor(4.7) 返回 4。math.floor(-3.2) 返回 -4,因为 -4 是不大于 -3.2 的最大整数。下一篇:python list 长度
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站