CKTIS / Python
math.trunc
Discards the fractional part of a real number and returns its integral part.
Version: Python 3.14; repository image, production runtime not attested
Syntax
math.trunc(x, /)Discards the fractional part of a real number and returns its integral part.
Positive and negative arguments both round toward zero.
Discarding the fraction moves 2.9 to 2 and −2.9 to −2. Both outputs are integers. For positive inputs this agrees with floor and for negative inputs with ceil. A numeric class can supply __trunc__.
import math
assert math.trunc(-2.9) == -2 and math.floor(-2.9) == -3
assert type(math.trunc(2.9)) is int
Examples
import math
print(math.trunc(2.9))
print(math.trunc(-2.9))
Result
2 -2
Discarding the fraction moves 2.9 to 2 and −2.9 to −2. Both outputs are integers. For positive inputs this agrees with floor and for negative inputs with ceil. A numeric class can supply `__trunc__`.