math.trunc

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

Submitted by admin on Wed, 01/27/2021 - 13:26