CKTIS / Python
math.trunc
Odreže decimalni del in za float vrne int.
Različica: Python 3.14; repository image, production runtime not attested
Sintaksa
math.trunc(x, /)Odreže decimalni del in za float vrne int.
Vrednosti 2,9 in −2,9 se približata ničli in dasta 2 oziroma −2. Pri negativnih vrednostih se rezultat ujema s ceil.
Številski tip lahko določi __trunc__.
import math
assert math.trunc(-2.9) == -2 and math.floor(-2.9) == -3
assert type(math.trunc(2.9)) is int
Primeri
import math
print(math.trunc(2.9))
print(math.trunc(-2.9))
Rezultat
2 -2
Številski tip lahko določi `__trunc__`.