Python3 floor()函数

该 floor() 方法返回x的地板 - 最大但不能大于x的整数。

语法

以下是 floor() 方法的语法:
import math

math.floor( x )

注:此函数无法直接访问,所以我们需要导入 math 模块,然后用数学静态对象调用这个函数。

参数

  • x -- 这是一个数字表达式。

返回值

该方法返回最大但不大于x的整数。

实例

下面的示例演示floor() 方法的使用。
#!/usr/bin/python3
import math   # This will import math module

print ("math.floor(-45.17) : ", math.floor(-45.17))
print ("math.floor(100.12) : ", math.floor(100.12))
print ("math.floor(100.72) : ", math.floor(100.72))
print ("math.floor(math.pi) : ", math.floor(math.pi))
当我们运行上面的程序,它会产生以下结果:
math.floor(-45.17) :  -46
math.floor(100.12) :  100
math.floor(100.72) :  100
math.floor(math.pi) :  3

上一篇: Python3循环 下一篇: Python3数字