How math.trunc() works in Python

The built-in math.trunc() function from the math module in Python is used to truncate values and return their fragments, also called integers.

Syntax

math.trunc(x)

Parameter

The function math.trunc() requires a number to be passed as a parameter. The number is returned with its decimal value removed.

Return value

A TypeError is raised if the passed parameter is not a number value.

Code

import math
print(math.trunc(9.11))
print(math.trunc(1.11))
print(math.trunc(4.20))

Free Resources