JavaScript (ES2026) reference · Math Methods and Constants
JavaScript Math.trunc() Method
Remove the fractional part of a number, rounding towards zero: Math.trunc(-4.7) is -4.
JavaScript (ES2026) Since ES2015
Syntax
Math.trunc(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number. |
Return value
An integer.
Examples
console.log(Math.trunc(4.7), Math.trunc(-4.7), Math.floor(-4.7));
Output
4 -4 -5
console.log(Math.trunc(7 / 2), 7 % 2);
Output
3 1
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
int()· Python
Related
Math.floor()· Round a number down to the integer below it: Math.floor(4.9) is 4 and Math.floor(-4.1) is -5.Math.ceil()· Round a number up to the next integer: Math.ceil(4.1) is 5 and Math.ceil(-4.1) is -4.- JavaScript Math · tutorial
- JavaScript Numbers · tutorial