math.trunc
Drop the fractional part of a number.
Python 3.13
math.trunc(x)Parameters
- xint | float
- A number.
Return value
An int.
Examples
A positive and a negative number
Python 3.13
import math
print(math.trunc(3.99), math.trunc(-3.99))3 -3
Difference from floor
Python 3.13
import math
print(math.trunc(-2.5), math.floor(-2.5))-2 -3
Details
For numbers it works like int(x): it rounds toward zero. It differs from math.floor for negative numbers: math.trunc(-2.5) gives -2, and math.floor(-2.5) gives -3.
