Round Number to - Node.js Math

Node.js examples for Math:Round

Description

Round Number to

Demo Code


Number.prototype.roundTo = function(num) {
  var resto = this%num;
  if (resto <= (num/2)) {
    return this-resto;
  } else {//  w ww. j  av  a 2 s  .c o  m
    return this+num-resto;
  }
};

Related Tutorials