The trunc() method returns the integer part of a number.
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.
Math.trunc(x)
Parameter | Require | Description |
---|---|---|
x | Required. | A number |
A Number
Return the integer part of a number:
//display the iteger part of 8.76. console.log(Math.trunc(8.76));/* w ww . j a v a2s . c om*/ console.log(Math.trunc(2.12346));