To find the floor of a number in Python, we can use the Python floor() function from the math module. The math.floor() Python function rounds a number down to the nearest integer.
import math
floor_of_5p2 = math.floor(5.2)
print(floor_of_5p2)
#Output:
5
The Python math module has many powerful functions which make performing certain calculations in Python very easy.
One such calculation which is very easy to perform in Python is finding the floor of a number.
We can find the floor of a number easily with the Python math module floor() function.
Below are some examples of how to use math.floor() in Python to round down and find the floor of numbers.
import math
print(math.floor(5.2))
print(math.floor(10.8))
print(math.floor(43.5))
print(math.floor(-12.3))
print(math.floor(-0.3))
#Output:
5.0
10.0
43.0
-13.0
-1.0
If you want to round up and get the ceiling of a number in Python, you can use the math.ceil() Python function. To round to the nearest integer, you can use the Python round() function.
If you are using pandas in Python you can find the ceiling of a column or Dataframe with the pandas floor() function.
Hopefully this article has been beneficial for you to learn how to get the floor in Python of a number with the math.floor() function.