floor()方法返回不大于x的最大整數(shù)(向下取整)。
語法
以下是floor()方法的語法:
import mathmath.floor( x )
注意:此函數(shù)是無法直接訪問的,所以我們需要導入math模塊,然后需要用math的靜態(tài)對象來調用這個函數(shù)。
參數(shù)
返回值
此方法返回不大于x的最大整數(shù)。
例子
下面的例子顯示了floor()方法的使用。
#!/usr/bin/pythonimport math # This will import math moduleprint "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.0math.floor(100.12) : 100.0math.floor(100.72) : 100.0math.floor(119L) : 119.0math.floor(math.pi) : 3.0
新聞熱點
疑難解答