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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Math.trunc(x)

Parameters

ParameterDescription
x A number.

Return value

An integer.

Examples

trunc() vs floor() for negativesTry it yourself
console.log(Math.trunc(4.7), Math.trunc(-4.7), Math.floor(-4.7));

Output

4 -4 -5
Integer division and remainderTry it yourself
console.log(Math.trunc(7 / 2), 7 % 2);

Output

3 1

Version history

VersionChange
JavaScript ES2015Added

In other languages

Was this page helpful?