Python math.trunc() Method
Python math.trunc(x) The method returns the truncated integer part of x, that is, the integer part with the fractional part ignored.
math.trunc(x) The method does not round a number up or down to the nearest integer, but simply removes the decimal part.
Syntax
The syntax of the math.trunc() method is as follows:
math.trunc(x)
Parameter Description:
- x -- required, a number. If x is not a number, a TypeError is returned. If the value is 0 or negative, a ValueError is returned.
Return Value
Returns an integer int representing the integer part of x.
Example
The following example returns the integer part of numbers:
Example
Import the math package
import
math
Output the integer part
(
math
.
trunc
(
2.77
)
)
(
math
.
trunc
(
8.32
)
)
(
math
.
trunc
(
99.29
)
)
Output result:
2
8
-99
Python math Module