Nodejs Number Format Pad padRight(max, c)

Here you can find the source of padRight(max, c)

Method Source Code

/*//w  w w  .  j a  v  a  2s  .c  om
   @max {Number}
   @c {String} :: optional
   return {String}
*/
Number.prototype.padRight = function(max, c) {
   return this.toString().padRight(max, c || '0');
};

Related

  1. padLeft(base, chr)
    Number.prototype.padLeft = function (base, chr) {
        var len = (String(base || 10).length - String(this).length) + 1;
        return len > 0 ? new Array (len).join(chr || '0') + this : this;
    };
    Array.prototype.compare = function (array) {
        if (!array)
            return false;
        if (this.length != array.length)
            return false;
    ...
    
  2. padLeft(base, chr)
    Number.prototype.padLeft = function (base, chr) {
        var len = (String(base || 10).length - String(this).length) + 1;
        return len > 0 ? new Array(len).join(chr || '0') + this : this;
    };
    
  3. padLeft(base,chr)
    Number.prototype.padLeft = function(base,chr) {
      var len = (String(base || 10).length - String(this).length)+1;
      return len > 0? new Array(len).join(chr || '0')+this : this;
    };
    
  4. padLeft(max, c)
    Number.prototype.padLeft = function(max, c) {
      return this.toString().padLeft(max, c || '0');
    };
    
  5. padLeft(n, str)
    Number.prototype.padLeft = function(n, str) {
        return Array(n-String(this).length+1).join(str||'0')+this;
    };
    
  6. padWithDigits(n)
    Number.prototype.padWithDigits = function (n) {  
      var txt = this.toString();
      while(txt.length < n) {
        txt = '0' + txt;
      return txt;  
    };
    
  7. padZeros(n)
    Number.prototype.padZeros = function(n){
      return this.toString().padZeros(n);
    };
    
  8. pad(length)
    Number.prototype.pad = function pad(length) {
      var str = '' + this;
      while (str.length < length) {
        str = '0' + str;
      return str;
    };
    
  9. LenWithZero(oCount)
    Number.prototype.LenWithZero = function(oCount) {
        var strText = this.toString();
        while (strText.length < oCount) {
            strText = '0' + strText;
        return strText;
    };