Full name
math.trunc
Library
math
Syntax
math.trunc(x)
Description
The math.trunc function returns the integer part of the number x (the part to the left of the decimal separator), keeping its sign.
Parameters
- x: Number whose integer part is to be obtained. It must be an integer or real number (complex numbers are not allowed).
Result
The math.trunc function returns an integer.
Examples
If the number passed as an argument is an integer, the function returns the same number:
math.trunc(4)
4
If it is a real number, it returns its integer part keeping the sign:
math.trunc(math.pi)
3
math.trunc(-math.pi)
-3