Python ceil() 関数

Python 数字Python 数値


説明

ceil() 関数は数値の切り上げ整数を返します。


構文

以下は ceil() メソッドの構文です:

import math

math.ceil( x )

注意:ceil() は直接アクセスできません。math モジュールをインポートし、静的オブジェクトを介してこのメソッドを呼び出す必要があります。


パラメータ

x -- 数値式。

戻り値

関数は数値の切り上げ整数を返します。

例

以下は ceil() メソッドを使用した例です:

#!/usr/bin/python
import math   # This will import math module

print "math.ceil(-45.17) : ", math.ceil(-45.17)
print "math.ceil(100.12) : ", math.ceil(100.12)
print "math.ceil(100.72) : ", math.ceil(100.72)
print "math.ceil(119L) : ", math.ceil(119L)
print "math.ceil(math.pi) : ", math.ceil(math.pi)

上記の例を実行した後の出力結果は次のとおりです:

math.ceil(-45.17) :  -45.0
math.ceil(100.12) :  101.0
math.ceil(100.72) :  101.0
math.ceil(119L) :  119.0
math.ceil(math.pi) : 4.0

Python 数字Python 数値

その他の拡張