Javascript Number fillZero(len)

Description

Javascript Number fillZero(len)


Number.prototype.fillZero = function (len)
{
 var s = this.toString(10);
 while (s.length<len) s = "0" + s;
 return s;//from w ww.jav a  2  s  .  c  o m
}

Javascript Number fillZero(length)



Number.prototype.fillZero = function(length){
 var string = String(this),
  zero = '0',/* www.  j  ava 2s.c om*/
  length = length || 2;

 while(string.length < length){
  string = zero + string;
  return string;
 }
}



PreviousNext

Related