Skip to content
Related Articles

Related Articles

Improve Article

floor() and ceil() function Python

  • Difficulty Level : Basic
  • Last Updated : 31 May, 2021

The floor() function:

floor() method in Python returns the floor of x i.e., the smallest integer not lesser than x. 
 

Syntax:
import math
math.floor(x)

Parameter: 
x-numeric expression. 

Returns: 
largest integer not greater than x.

Below is the Python implementation of floor() method: 

Python




# Python program to demonstrate the use of floor() method
 
# This will import math module
import math  
 
# prints the ceil using floor() method
print "math.floor(-23.11) : ", math.floor(-23.11)
print "math.floor(300.16) : ", math.floor(300.16)
print "math.floor(300.72) : ", math.floor(300.72)

Output: 

math.floor(-23.11) :  -24.0
math.floor(300.16) :  300.0
math.floor(300.72) :  300.0

 

The ceil() Function:

The method ceil() in Python returns a ceiling value of x i.e., the largest integer not greater than x. 
 



Syntax: 
import math
math.ceil(x)
Parameter:
x:This is a numeric expression.
Returns: 
Smallest integer not less than x.

Below is the Python implementation of ceil() method: 

Python




# Python program to demonstrate the use of ceil() method
 
# This will import math module
import math  
 
# prints the ceil using ceil() method
print "math.ceil(-23.11) : ", math.ceil(-23.11)
print "math.ceil(300.16) : ", math.ceil(300.16)
print "math.ceil(300.72) : ", math.ceil(300.72)

Output: 

math.ceil(-23.11) :  -23.0
math.ceil(300.16) :  301.0
math.ceil(300.72) :  301.0

 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :