Math.trunc()
Math.trunc(x) → number
Returns the integer portion of x, removing any fractional digits.
Removes the fractional part of x, rounding toward zero. Unlike Math.floor(), negative values are rounded up.
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| x | number | optional | — | A number. |
Returns
number
The integer part of x.
Example
let t = Math.trunc(-4.7); // -4