Easy Tutorial
❮ Prop Audio Muted Dom Obj Body ❯

JavaScript trunc() Method

JavaScript Math Object

Example

Remove the decimal part of a number:

let x = Math.trunc(8.76);

Output result:


Definition and Usage

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


Browser Support

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes

Syntax

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

JavaScript Math Object

❮ Prop Audio Muted Dom Obj Body ❯