Python3 floor() 函數
描述
floor(x) 返回數字的下舍整數,小於或等於 x。
語法
以下是 floor() 方法的語法:
import math math.floor( x )
注意:floor()是不能直接訪問的,需要導入 math 模組,通過靜態對象調用該方法。
參數
- x -- 數值運算式。
返回值
返回小於或等於 x 的整數。實例
以下展示了使用 floor() 方法的實例:
#!/usr/bin/python import math # 導入 math 模組 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