Skip to content

trunc ​

The trunc() method truncates the decimal part of a number, returning only the integer part. Unlike floor(), it behaves the same for positive and negative numbers by simply removing the decimals.

Interactive example ​

Syntax ​

typescript
function trunc<
	GenericInput extends number,
>(input: GenericInput): number

Parameters ​

  • input: The number whose decimal part you want to truncate.

Return value ​

The integer part of the given number (removes decimals without rounding).

See also ​

  • round - Rounds to the nearest integer
  • floor - Rounds down
  • ceil - Rounds up

Sources ​

Released under the MIT license.