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