Javascript - Math trunc() Method

The trunc() method returns the integer part of a number.

Description

The trunc() method returns the integer part of a number.

This method will NOT round the number up/down to the nearest integer, but simply remove the decimals.

Syntax

Math.trunc(x)

Parameter Values

Parameter Require Description
x Required. A number

Return

A Number

Example

Return the integer part of a number:

Demo

//display the iteger part of 8.76.
console.log(Math.trunc(8.76));/*  w  w w  .  ja  v  a  2 s  . co m*/

console.log(Math.trunc(2.12346));

Result