Python math.ceil()メソッド
例
数値を最も近い整数に切り上げます。
# Import math library
import math
# Round a number upward to its
nearest integer
print(math.ceil(1.4))
print(math.ceil(5.3))
print(math.ceil(-5.3))
print(math.ceil(22.6))
print(math.ceil(10.0))
定義と使用法
このmath.ceil()
メソッドは、必要に応じて数値を最も近い整数に切り上げ、結果を返します。
ヒント:数値を最も近い整数に切り捨てるには、
math.floor()
メソッドを確認してください。
構文
math.ceil(x)
パラメータ値
Parameter | Description |
---|---|
x | Required. Specifies the number to round up |
技術的な詳細
戻り値: | 丸められたint 数値を表す値。 |
---|---|
変更ログ: | Python 3+:値を返しint ますPython 2.x:値を返し float ます。 |