Python math.floor() Method

Python math 模块Python math Module

Python math.floor(x)The method rounds x down to the nearest integer.

math.ceil()The method rounds a number up to the nearest integer.

Syntax

The syntax of the math.floor() method is as follows:

math.floor(x)

Parameter Description:

  • xx -- Required, a number. If x is not a number, returns TypeError.

Return Value

Returns an integer int representing the rounded-down number.

Example

The following example returns the number rounded down to the nearest integer:

Example

# Import the math package
import math

# Output the number rounded 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))

Output:

0
1
5
-6
22
10

Python math 模块Python math Module

Other Extensions