該 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