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