Nodejs Float Round roundTo(num)

Here you can find the source of roundTo(num)

Method Source Code

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

Related

  1. round5()
    Number.prototype.round5 = function() {
      return ((this)- (this % 5));
    
  2. roundDecimal()
    Number.prototype.roundDecimal = function() {
      return Math.roundDecimal(this);
    };
    
  3. roundMoney(decimals = 2)
    Number.prototype.roundMoney = Number.prototype.toObject || function roundMoney(decimals = 2) {
      return Number((Math.round(this + "e" + decimals) + "e-" + decimals));
    };
    
  4. roundNumber.prototype.round || (precision)
    Number.prototype.round = Number.prototype.round || function (precision) {
      return Math.round(this * Math.pow(10, (precision || 2))) / Math.pow(10, (precision || 2))
    
  5. roundTo()
    Number.prototype.roundTo = function() {
        return 32 * Math.round(this / 32);
    
  6. roundToFixed(radix)
    Number.prototype.roundToFixed = function (radix) {
        var val = this;
        radix = radix || 0;
        val *= Math.pow(10, radix);
        val = Math.round(val);
        val /= Math.pow(10, radix);
        return val;
    };
    
  7. roundToPrec(precision)
    Number.prototype.roundToPrec = function(precision)
        var power = Math.pow(10, precision || 0);
        return Math.round(this * power) / power;
    
  8. roundToTwoDPoints()
    Number.prototype.roundToTwoDPoints = function() {
      if (isNaN(this)) {
        console.log(this);
        console.dir(this);
        throw new Error('Not a number!');
      return Math.round((this + 0.00001) * 100) / 100;
    };
    
  9. ceil()
    Number.prototype.ceil = function(){
        return Math.ceil(this);
    };