The math.trunc()
function is used to truncate a number to its integer part. It simply removes the decimal part of the given number, returning the integer.
math.trunc(x)
Where, parameter x
is the number to be truncated.
If the input is a float (decimal) number, the math.trunc()
function removes the digits after the decimal point and returns the integer. If the input is an integer, the function simply returns the same integer.
import math
math.trunc(5)
//5
math.trunc(6.8)
//6
math.trunc(-6.8)
//-6
math.trunc(100.2)
//100
math.trunc(3.142)
//3