Javascript Number roundTo(num)

Description

Javascript Number roundTo(num)




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



PreviousNext

Related