Nodejs Number Format addZero()

Here you can find the source of addZero()

Method Source Code

Number.prototype.addZero=function(){

      var val=(this+"");
      val=((2>val.length)?("0"+val):val);
      return val;
}

Related

  1. formatHashrate(rate)
    var formatHashrate = function(rate) {
        rate = parseFloat(rate); 
        unit = 'H/s';
        if (rate >= 1000) { rate /= 1000; unit = 'KH/s'; }
        if (rate >= 1000) { rate /= 1000; unit = 'MH/s'; }
        if (rate >= 1000) { rate /= 1000; unit = 'GH/s'; }
        if (rate >= 1000) { rate /= 1000; unit = 'TH/s'; }
        if (rate >= 1000) { rate /= 1000; unit = 'PH/s'; }
        return (rate.toFixed(2) + ' ' + unit);
    ...
    
  2. withCommas()
    Number.prototype.withCommas = function() {
        return this.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    };
    
  3. withCommas()
    Number.prototype.withCommas = function() {
      var x = 3;
      var y = parseFloat(this).toString().reverse();
      while (x < y.length) {
        y = y.substring(0, x) + "," + y.substring(x); 1
        x += 4;
      return y.reverse();
    };
    ...
    
  4. withCommas()
    Number.prototype.withCommas = function() {
      var num = this;
      return this.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    
  5. addTrailingZero()
    Number.prototype.addTrailingZero = function(){
      if(this < 10)  return "0"+this;
      else  return this;
    };
    
  6. comma()
    var d3 = /(\d+)(\d{3})/;
    Number.prototype.comma = function() {
        var s = this.toString();
        while (d3.test(s)) s = s.replace(d3, '$1,$2');
        return s;
    };
    
  7. commafy()
    Number.prototype.commafy = function () {
      return String(this).commafy();
    
  8. commafy()
    Number.prototype.commafy = function () {
      return String(this).commafy();
    String.prototype.commafy = function () {
      return this.replace(/(^|[^\w.])(\d{4,})/g, function($0, $1, $2) {
        return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, "$&,");
      });
    
  9. format()
    Number.prototype.format = function () {
      var str = this.toString();
      var Re = /[^0-9]/g;
      var ReN = /(-?[0-9]+)([0-9]{3})/;
      str = str.replace(Re,'');              
      while (ReN.test(str)) { 
        str = str.replace(ReN, "$1,$2"); 
      return str;
    ...