Python math.floor() メソッド
Python math.floor(x)このメソッドは x を最も近い整数に切り捨てます。
math.ceil()このメソッドは数値を最も近い整数に切り上げます。
構文
math.floor() メソッドの構文は次のとおりです。
math.floor(x)
引数の説明:
- xx -- 必須、数値。x が数値でない場合は TypeError を返します。
戻り値
切り捨てた数値を表す整数 int を返します。
例
以下の例は、最も近い整数に切り捨てた値を返します。
例
# math パッケージをインポート
import math
# 最も近い整数に切り捨てた数値を出力
print(math.floor(0.6))
print(math.floor(1.4))
print(math.floor(5.3))
print(math.floor(-5.3))
print(math.floor(22.6))
print(math.floor(10.0))
import math
# 最も近い整数に切り捨てた数値を出力
print(math.floor(0.6))
print(math.floor(1.4))
print(math.floor(5.3))
print(math.floor(-5.3))
print(math.floor(22.6))
print(math.floor(10.0))
出力結果:
0 1 5 -6 22 10その他の拡張
Python math モジュール