JavaScript trunc() Method
Example
Removes the fractional part of a number:
let x = Math.trunc(8.76);
Output result:
8
Try it »
Definition and Usage
The Math.trunc() method removes the fractional 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 value
| Parameters | 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