Math.trunc()

Truncate a number to a given precision.

Signature

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

Description

Gets the number x truncated to precision, depending on the underlying representation of the floating point number.

Parameters

Parameter Type Required Description

x

Number

Yes

A number.

precision

Number

Yes

Precision to truncate x to.

Return value

Type Description

Number

Value of x truncated to 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

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!