簡單介紹Python中的floor()方法
更新時間:2015年05月15日 09:11:11 投稿:goldensun
這篇文章主要介紹了Python中的floor()方法,是Python入門的基礎知識,需要的朋友可以參考下
floor()方法返回不大于x的最大整數(shù)(向下取整)。
語法
以下是floor()方法的語法:
import math math.floor( x )
注意:此函數(shù)是無法直接訪問的,所以我們需要導入math模塊,然后需要用math的靜態(tài)對象來調用這個函數(shù)。
參數(shù)
- x -- 這是一個數(shù)值表達式。
返回值
此方法返回不大于x的最大整數(shù)。
例子
下面的例子顯示了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
相關文章
把大數(shù)據(jù)數(shù)字口語化(python與js)兩種實現(xiàn)
當出現(xiàn)萬以上的整型數(shù)字時,經(jīng)常要把它們口語化比較直觀。下面分享兩段代碼,python與js的2013-02-02

