JavaScript Math.trunc() Method
The Math.trunc() static method removes the decimal part of a number, leaving the whole-number part.
Description
The Math.trunc() static method returns the integer part of a number by removing any fractional digits. Unlike Math.floor(), it always moves towards zero, so Math.trunc(-4.7) is -4.
It's equivalent to Math.floor() for positive numbers and Math.ceil() for negative ones. Unlike the old bitwise trick x | 0, it works correctly for numbers outside the 32-bit integer range.
Math.trunc() is a good choice when splitting a number into whole and fractional parts, such as converting seconds into whole minutes. Non-numeric values give NaN. Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.
Syntax
Math.trunc(x)Parameters
- xA number.
Return Value
The integer part of x.
Example
Browser Support
The following information will show you the current browser support for the Math.trunc() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





