The floor() and ceil() Functions in Python

The floor() and ceil() Functions in Python

In this tutorial, we will learn how to use the floor() and ceil() functions of the math module in Python.

The floor() Function:

The floor() function is used for getting the floor integer of “X”, which mean the largest integer value, which is not greater than “X”, basically the nearest round-down number of it.

Syntax:

Parameter:

We can pass the numeric expression.

Returns:

It returns the largest integer value that is not greater than “X”.

Let’s see an example to get an idea of implementing the floor() function in Python.

Example:

Output:

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

The ceil() Function:

The ceil() function of the math module in Python is used for getting the ceiling value of “X” in return, which means the smallest integer value, which is not less than “X”, basically, the nearest round-off number of it.

Syntax:

Parameter:

We can pass the numeric expression.

Returns:

It returns the smallest integer value that is not less than “X”.

Let’s see an example to get an idea of implementing the ceil() function in Python.

Example:

Output:

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

Conclusion

In this tutorial, we discussed how to implement the floor() and ceil() functions of the math module in Python.


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263374.html

(0)
上一篇 2022年5月30日
下一篇 2022年5月30日

相关推荐

发表回复

登录后才能评论