带有Python示例的math.floor()方法

Python math.floor() 方法

math.floor()方法数学模块的库方法,用于获取给定数字的下限值,用于获取数字的下限值,它接受数字/数字表达式并返回最大整数(整数)值,不大于数字。

注意:如果数字是整数值,则对于浮点值很有用–它返回相同的值。

它的语法 math.floor() 方法:

    math.floor(n)

Parameter(s): n-一个数字或数字表达式。

返回值: int –返回一个整数值–它是给定数字的最大整数值,但不大于n。

示例

    Input:
    n = 10.23

    # 函数调用
    print(math.floor(n))

    Output:
    10

Python代码查找给定数字的底值

# Python代码查找给定数字的底值
# 导入数学
import math

# 数
n1 = 10.23
n2 = 10.67
n3 = 10
n4 = -10.23
n5 = 0

# 打印底价
print("floor(n1): ", math.floor(n1))
print("floor(n2): ", math.floor(n2))
print("floor(n3): ", math.floor(n3))
print("floor(n4): ", math.floor(n4))
print("floor(n5): ", math.floor(n5))

输出结果

floor(n1):  10
floor(n2):  10
floor(n3):  10
floor(n4):  -11
floor(n5):  0