Nodejs Utililty Methods Number Format Pad

List of utility methods to do Number Format Pad

Description

The list of methods to do Number Format Pad are organized into topic(s).

Method

padLeft(max, c)
Number.prototype.padLeft = function(max, c) {
  return this.toString().padLeft(max, c || '0');
};
padLeft(n, str)
Number.prototype.padLeft = function(n, str) {
    return Array(n-String(this).length+1).join(str||'0')+this;
};
padRight(max, c)
Number.prototype.padRight = function(max, c) {
  return this.toString().padRight(max, c || '0');
};
padWithDigits(n)
Number.prototype.padWithDigits = function (n) {  
  var txt = this.toString();
  while(txt.length < n) {
    txt = '0' + txt;
  return txt;  
};
padZeros(n)
Number.prototype.padZeros = function(n){
  return this.toString().padZeros(n);
};
pad(length)
Number.prototype.pad = function pad(length) {
  var str = '' + this;
  while (str.length < length) {
    str = '0' + str;
  return str;
};
LenWithZero(oCount)
Number.prototype.LenWithZero = function(oCount) {
    var strText = this.toString();
    while (strText.length < oCount) {
        strText = '0' + strText;
    return strText;
};
leadingZero(length)
Number.prototype.leadingZero = function(length) {
    return ('0'+this).slice(-length);
leftZeroFill(number, targetLength)
function leftZeroFill(number, targetLength) {
    var output = number + '';
    while (output.length < targetLength) {
        output = '0' + output;
    return output;
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;
};
...