Javascript Number round(decimals)

Description

Javascript Number round(decimals)


Number.prototype.round = function (decimals) {
  if (decimals) {
    var pow = Math.pow(10, decimals);
    return Math.round(this * pow) / pow;
  }/*from   w  w  w  .j  av a 2s . co  m*/
  else return Math.round(this * 100) / 100;
};



PreviousNext

Related