Javascript Number roundToTwoDPoints()

Description

Javascript Number roundToTwoDPoints()


//  ==========================
//  ROUND TO 2 DECIMAL POINTS
//  ==========================
Number.prototype.roundToTwoDPoints = function() {
  if (isNaN(this)) {
    console.log(this);/*from   w ww  .ja va2s .c  o  m*/
    console.dir(this);
    throw new Error('Not a number!');
  }
  return Math.round((this + 0.00001) * 100) / 100;
};



PreviousNext

Related