Math.trunc()
Returns the integer part of a number by removing any fractional digits.
Syntax
Math.trunc(x) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | number | Yes | The number to truncate. |
Returns
number — The integer part of x with the fraction removed.
Examples
console.log(Math.trunc(4.7), Math.trunc(-4.7));
Output
4 -4
console.log(Math.trunc(0.99));
Output
0
Notes
Simply drops the fractional part, rounding toward zero. Unlike `floor`/`ceil`
the rounding direction does not depend on sign.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 38 |
| firefox | 25 |
| safari | 8 |
| edge | 12 |
| node | 0.12 |