Round to specified number of places - Node.js Math

Node.js examples for Math:Round

Description

Round to specified number of places

Demo Code


Number.prototype.round = function(places) {
  if(!places) return Math.round(this);
  var tmp = Math.pow(10,places);
  return Math.round(this * tmp) / tmp;
};

Related Tutorials