Python math.floor() Method
Example
Round a number downward to its nearest integer:
# Import math library
import math
# Round a number downward to its
nearest integer
print(math.floor(1.4))
print(math.floor(5.3))
print(math.floor(-5.3))
print(math.floor(22.6))
Try it Yourself »
Definition and Usage
The math.floor()
method rounds a number downwards to the nearest integer, and returns the result.
Syntax
math.floor(x)
Parameter Values
Parameter | Description |
---|---|
x | Required. The number you want to round downwards. If x is not a number, a TypeError occurs |
Technical Details
Return Value: | An int value, representing the rounded number |
---|---|
Python Changelog: | Returns an int value in Python 3+, while it returns a float in Python 2 |