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その他の拡張