Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The Math.trunc() static method returns the integer part of a number by removing any fractional digits.
A number.
The integer part of x.
The way Math.trunc() works is more straightforward than the other three Math methods: Math.floor(), Math.ceil() and Math.round(); it truncates (cuts off) the dot and the digits to the right of it, no matter whether the argument is a positive or negative number.
Because trunc() is a static method of Math, you always use it as Math.trunc(), rather than as a method of a Math object you created (Math is not a constructor).
Warning: This is not a polyfill for Math.trunc() because of non-negligible edge cases.
Bitwise operations convert their operands to 32-bit integers, which people have historically taken advantage of to truncate float-point numbers. Common techniques include:
Beware that this is essentially toInt32, which is not the same as Math.trunc. When the value does not satisfy -231 - 1 < value < 231 (-2147483649 < value < 2147483648), the conversion would overflow.
Only use ~~ as a substitution for Math.trunc() when you are confident that the range of input falls within the range of 32-bit integers.
| ECMAScript® 2027 Language Specification # sec-math.trunc |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.