Standard built-ins

Math.trunc()

Try the free JavaScript compiler

Discards fractional parts toward zero; may produce signed zero. Converts x to Number; BigInt conversion throws TypeError.

Formal Syntax & Structure

javascript syntaxjavascript
Math.trunc(x)

Parameters & Attributes

NameTypeDescription
xnumberNumber input or value coercible to Number.

Return Value

number

Result of the numerical operation, possibly NaN.

Working Example

Example Snippetjavascript
console.log(Math.trunc(-2.9));
JavaScript Reference