Python math.floor() Method
Example
Round numbers down to the nearest integer:
# Import math library
import math
# Round numbers down to the
nearest integer
print(math.floor(0.6))
print(math.floor(1.4))
print(math.floor(5.3))
print(math.floor(-5.3))
print(math.floor(22.6))
print(math.floor(10.0))
Try it Yourself »
Definition and Usage
The math.floor()
method rounds a number DOWN
to the nearest integer, if necessary, and returns the result.
Tip: To round a number UP to the nearest integer, look at the
math.ceil()
method.
Syntax
math.floor(x)
Parameter Values
Parameter | Description |
---|---|
x | Required. Specifies the number to round down |
Technical Details
Return Value: | An int value, representing the rounded number |
---|---|
Change Log: | Python 3+ : Returns an int valuePython 2.x : Returns a float value |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.