Nodejs Float Round ceilMagnitude()

Here you can find the source of ceilMagnitude()

Method Source Code

Number.prototype.ceilMagnitude = function(){
  if (this > 1) {
    var magnitude = Math.pow(10, (this.toString().length - 1));
    return Math.ceil(this / magnitude) * magnitude;
  } else {//  w  w  w  . jav  a 2s. com
    return 1;
  }
};

var objectLength = function objectLength(object) {
  var size = 0, key;
  for (key in object) {
    if (object.hasOwnProperty(key)) size++;
  }
  return size;
};

Related

  1. roundTo(num)
    Number.prototype.roundTo = function(num) {
      var resto = this%num;
      if (resto <= (num/2)) {
        return this-resto;
      } else {
        return this+num-resto;
    };
    
  2. 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;
    };
    
  3. roundToPrec(precision)
    Number.prototype.roundToPrec = function(precision)
        var power = Math.pow(10, precision || 0);
        return Math.round(this * power) / power;
    
  4. 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;
    };
    
  5. ceil()
    Number.prototype.ceil = function(){
        return Math.ceil(this);
    };
    
  6. floor()
    Number.prototype.floor = function(){
        return Math.floor(this);
    };
    
  7. floor(scale)
    Number.prototype.floor = function (scale) {
        scale = Number(scale);
        if (isNaN(scale) || scale !== Number(scale.toFixed(0))) {
            return ;
        var ratio = Math.pow(10,scale);
        return Math.floor(this * ratio) / ratio;
    };