Favorites

JavaScript Math.trunc() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.trunc()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

console.log(Math.trunc(4.7));
console.log(Math.trunc(-4.7));
console.log(Math.floor(-4.7));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee