Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / Python

math.floor

Restituisce il più grande intero che non supera x.

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

Sintassi

math.floor(x, /)

Restituisce il più grande intero che non supera x.

Per 2,9 è 2. Per −2,1 il valore −2 sarebbe troppo grande, quindi il risultato è −3. Un valore già intero rimane invariato.

Un tipo numerico può definire __floor__.

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

Esempi

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

Risultato

2
-3

Un tipo numerico può definire `__floor__`.

Fonti