Python floor() 函數
描述
floor() 返回數字的下舍整數。
語法
以下是 floor() 方法的語法:
import math math.floor( x )
注意:floor()是不能直接訪問的,需要導入 math 模組,通過靜態對象調用該方法。
參數
- x -- 數值運算式。
返回值
返回數字的下舍整數。實例
以下展示了使用 floor() 方法的實例:
#!/usr/bin/python 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(119L) : ", math.floor(119L) print "math.floor(math.pi) : ", math.floor(math.pi)
以上實例運行後輸出結果為:
math.floor(-45.17) : -46.0 math.floor(100.12) : 100.0 math.floor(100.72) : 100.0 math.floor(119L) : 119.0 math.floor(math.pi) : 3.0