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