#import the math module
import math
#use the floor() function
print(math.floor(0.5))
print(math.floor(9.9))
The math.floor()
function returns the floor value of a real number, which is the largest integer less than or equal to the number. For example, the floor value of 4.7 is 4, because 4 is the largest integer less than or equal to 4.7. Similarly, the floor value of -3.2 is -4, because -4 is the largest integer less than or equal to -3.2.
math.floor(x)
x |
The number whose floor value is to be determined. It can be any valid real number i.e a floating point value or an integer. |
The function returns the floor value of x
. If x
is an integer the return value is just as same as x
.
import math
math.floor(3)
//3
math.floor(-4.0)
//-4
math.floor(-5.5)
//-6
math.floor(5.5)
//5
math.floor(9.9)
//9
math.floor(-18.6)
//-19
math.floor(100.9)
//100
Compare math.floor()
with math.ceil()
which returns the smallest integer greater then or equal to the input.