Python math.trunc() Method
Python math.trunc(x)The method returns the truncated integer part of x, i.e., it returns the integer part and ignores the decimal part.
math.trunc(x)The method does not round the number up/down to the nearest integer; it 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 a negative number, 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 a number:
Example
# Import the math package
import math
# Output the integer part
print(math.trunc(2.77))
print(math.trunc(8.32))
print(math.trunc(-99.29))
import math
# Output the integer part
print(math.trunc(2.77))
print(math.trunc(8.32))
print(math.trunc(-99.29))
Output Result:
2 8 -99Other Extensions
Python math Module