Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

math.floor

Rounds downward to the greatest integer less than or equal to the argument.

Version: Python 3.14; repository image, production runtime not attested

Syntax

math.floor(x, /)

Rounds downward to the greatest integer less than or equal to the argument.

A negative fractional value rounds farther from zero, unlike truncation.

For 2.9, 2 is the greatest integer below the argument. For −2.1, −2 would be above the argument, so the answer is −3. An integral input needs no adjustment. Custom numeric types can implement __floor__.

import math
assert math.floor(-2.1) == -3 < math.trunc(-2.1)
assert math.floor(2.0) == 2

Examples

import math
print(math.floor(2.9))
print(math.floor(-2.1))

Result

2
-3

For 2.9, 2 is the greatest integer below the argument. For −2.1, −2 would be above the argument, so the answer is −3. An integral input needs no adjustment. Custom numeric types can implement `__floor__`.

Sources