Python数字floor()方法

Python数字fabs()方法返回x的底部,即不大于x的最大整数。

语法

以下是floor()方法的语法 -

import math

math.floor( x )

注意 - 此方法不能直接访问,需要导入math模块,然后使用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

上一篇: Python数字 下一篇: Python字符串