Python floor() and ceil() Functions

Python Floor And Ceil Functions

This is a detailed tutorial of Python floor() and ceil() functions. Learn to find the floor and ceiling value of any numerical value in using the math module.

Use of floor() and ceil() Functions

The math module which comes pre-installed with Python. This module includes two object type functions, math.floor() and math.ceil(). Both of these functions take a numerical value as an argument.

  • The floor() function will return the mathematical floor value of that numerical value passed as argument i.e. the largest integer value which is not greater than the numerical value passed.
  • The ceil() function will return the mathematical ceiling value i.e. smallest integer value that is not less than the passed numerical value.

Find more about floor and ceiling values here.


You must include the math module first in your program and then you can use the floor() and ceil() functions anywhere as the object-specific function of the math module.

In the above syntax, x is any numeric value or expression.


The following two examples illustrate the use of floor() and ceil() functions respectively.

Example 1.

The following code calculates the floor value of three different numerical values.

Python Floor() Function Example

Example 2.

The code given below calculates the ceiling value of three different numerical values which are the same as the numerical values used in the above example.

Ceil() Function Example Python

I hope you found this guide useful. If so, do share it with others who are willing to learn Python. If you have any questions related to this article, feel free to ask us in the comments section.

And do not forget to subscribe to WTMatter!

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

Your email address will not be published. Required fields are marked *