logo

Python の Floor() 関数と ceil() 関数

このチュートリアルでは、Python の math モジュールの Floor() 関数と ceil() 関数の使用方法を学びます。

Floor() 関数:

Floor() 関数は、「X」の下限整数を取得するために使用されます。これは、「X」以下の最大の整数値、基本的にその最も近い切り捨て数値を意味します。

構文:

 math.floor(X) 

パラメータ:

数値式を渡すことができます。

戻り値:

「X」以下の最大の整数値を返します。

Python での Floor() 関数の実装方法を理解するために例を見てみましょう。

例:

 import math as M # printing the floor value by using floor() function of math module print ('The floor value of math.floor(-54.21) is: ', M.floor(-54.21)) print ('The floor value of math.floor(432.56) is: ', M.floor(432.56)) print ('The floor value of math.floor(320.62) is: ', M.floor(320.62)) 

出力:

 The floor value of math.floor(-54.21) is: -55 The floor value of math.floor(432.56) is: 432 The floor value of math.floor(320.62) is: 320 

ceil() 関数:

Python の数学モジュールの ceil() 関数は、返される「X」の上限値を取得するために使用されます。これは、「X」以上の最小の整数値、基本的には最も近い四捨五入数を意味します。それ。

構文:

 math.ceil(X) 

パラメータ:

数値式を渡すことができます。

戻り値:

「X」以上の最小の整数値を返します。

Python で ceil() 関数を実装する方法を理解するために例を見てみましょう。

例:

 import math as M # printing the ceiling value by using ceil() function of math module print ('The ceiling value of math.ceil(-54.21) is: ', M.ceil(-54.21)) print ('The ceiling value of math.ceil(432.56) is: ', M.ceil(432.56)) print ('The ceiling value of math.ceil(320.62) is: ', M.ceil(320.62)) 

出力:

 The ceiling value of math.ceil(-54.21) is: -54 The ceiling value of math.ceil(432.56) is: 433 The ceiling value of math.ceil(320.62) is: 321 

結論

このチュートリアルでは、Python で数学モジュールの Floor() 関数と ceil() 関数を実装する方法について説明しました。