JavaScript trunc()Method

Math 对象参考手册JavaScript Math Object

Example

Remove the decimal part of the number:

let x = Math.trunc(8.76);

Output result:

8

Try it yourself »

Definition and Usage

The Math.trunc() method removes the decimal part of a number, keeping only the integer part.


Browser Support

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes

Syntax

Math.trunc(x)

Parameter Values

Parameter Description
x Any number.

Return Value

Type Description
Number The integer part of the given number.

Technical Details

JavaScript Version: 1.0


More Examples

Math.trunc(13.37)    // 13
Math.trunc(42.84)    // 42
Math.trunc(0.123)    //  0
Math.trunc(-0.123)   // -0
Math.trunc("-1.123") // -1
Math.trunc(NaN)      // NaN
Math.trunc("foo")    // NaN
Math.trunc()         // NaN


Math 对象参考手册JavaScript Math Object

Other Extensions