Design & Download
Your JS Library
in Seconds!!!

Snippet: trunc() - Integral Part of a Number

Written by Christopher West (cwest) on November 24, 2015.
Just gets the integral part of a number.
function trunc(num) {
  return Math[num < 0 ? 'ceil' : 'floor'](num);
}

Since we have a function to get the non-integral part of a number it only makes sense to also have a function to get the integral part of a number.

trunc(num) API Documentation

Parameters

  1. num {number}:
    The number for which only the integral part shall be returned.

Returns

Returns the integral part of num while keeping the sign.