Nodejs Number Format Pad LenWithZero(oCount)

Here you can find the source of LenWithZero(oCount)

Method Source Code

Number.prototype.LenWithZero = function(oCount) {
    var strText = this.toString();
    while (strText.length < oCount) {
        strText = '0' + strText;
    }/*  ww  w  . ja v  a  2 s .  c o  m*/
    return strText;
};

Related

  1. padLeft(n, str)
    Number.prototype.padLeft = function(n, str) {
        return Array(n-String(this).length+1).join(str||'0')+this;
    };
    
  2. padRight(max, c)
    Number.prototype.padRight = function(max, c) {
      return this.toString().padRight(max, c || '0');
    };
    
  3. padWithDigits(n)
    Number.prototype.padWithDigits = function (n) {  
      var txt = this.toString();
      while(txt.length < n) {
        txt = '0' + txt;
      return txt;  
    };
    
  4. padZeros(n)
    Number.prototype.padZeros = function(n){
      return this.toString().padZeros(n);
    };
    
  5. pad(length)
    Number.prototype.pad = function pad(length) {
      var str = '' + this;
      while (str.length < length) {
        str = '0' + str;
      return str;
    };
    
  6. leadingZero(length)
    Number.prototype.leadingZero = function(length) {
        return ('0'+this).slice(-length);
    
  7. leftZeroFill(number, targetLength)
    function leftZeroFill(number, targetLength) {
        var output = number + '';
        while (output.length < targetLength) {
            output = '0' + output;
        return output;
    
  8. leftZeroPad(numZeros)
    Number.prototype.leftZeroPad = function(numZeros) {
            var n = Math.abs(this);
            var zeros = Math.max(0, numZeros - Math.floor(n).toString().length );
            var zeroString = Math.pow(10,zeros).toString().substr(1);
            if( this < 0 ) {
                    zeroString = '-' + zeroString;
            return zeroString+n;
    };
    ...
    
  9. zeroPad(len)
    Number.prototype.zeroPad = function (len) {
      var s = String(this);
      var c = '0';
      len = len || 2;
      while (s.length < len) {
        s = c + s;
      return s;
    };
    ...