Nodejs Number Format Pad padLeft(base, chr)

Here you can find the source of padLeft(base, chr)

Method Source Code

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;
};

Related

  1. pad(size)
    'use strict';
    Number.prototype.pad = function(size) {
      if(typeof(size) !== "number"){size = 2;}
      var s = String(this);
      while (s.length < size) s = "0" + s;
      return s;
    
  2. pad(size)
    Number.prototype.pad = function(size) {
      var s = String(this);
      if (typeof(size) !== "number") {
        size = 2;
      while (s.length < size) {
        s = "0" + s;
      return s;
    ...
    
  3. pad(size, decimalSize, decimalChar)
    Number.prototype.pad = function (size, decimalSize, decimalChar) {
        if (!decimalChar) decimalChar = '.';
        var str = this.toString();
        str = str.split(".");
        var result = str[0].pad("0", size ? size : 0);
        if (str.length==2){
            result += decimalChar + str[1].pad("0", decimalSize, true);
        return result;
    ...
    
  4. 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;
    function formatDate(d) {
        return [(d.getFullYear()).padLeft(),
                (d.getMonth() + 1).padLeft(),
                d.getDate().padLeft()].join('-') +
            ' ' +
    ...
    
  5. 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;
    ...
    
  6. 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;
    };
    
  7. padLeft(max, c)
    Number.prototype.padLeft = function(max, c) {
      return this.toString().padLeft(max, c || '0');
    };
    
  8. padLeft(n, str)
    Number.prototype.padLeft = function(n, str) {
        return Array(n-String(this).length+1).join(str||'0')+this;
    };
    
  9. padRight(max, c)
    Number.prototype.padRight = function(max, c) {
      return this.toString().padRight(max, c || '0');
    };