The Math.trunc(number) function

The Math.trunc() function returns the integer part of a number by removing any fractional digit. Here is an example to demonstrate this:

console.log(Math.trunc(11.17));console.log(Math.trunc(-1.112));

The output is as follows:

11-1

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.