Math.trunc()

Truncate a Number to a given precision.

Signature

Math.trunc(x: Number, precision: Number) => Number

Description

Returns a provided Number, truncated to a specified precision, depending on the underlying representation of the floating point number.

Parameters

Parameter Type Required Description

x

Number

true

A number.

precision

Number

true

Precision to truncate to.

Return value

Type Description

Number

The provided number, truncated to the specified precision.

Examples

Math.trunc(12.123, 1)
12.1

 

Note that the result might reflect the underlying imprecision of the representation of a floating point number:

Math.trunc(12.123, 3)
12.122
\