Rounding a Number to x Decimal Places - Node.js Math

Node.js examples for Math:Round

Description

Rounding a Number to x Decimal Places

Demo Code

// Rounding a Number to x Decimal Places
function roundTo(base, precision) {
  var m = Math.pow(10, precision);
  var a = Math.round(base * m) / m;
  return a;/*from ww  w  .  j a v  a  2s .c  o  m*/
}

Related Tutorials