Javascript Number pad(intPad)

Description

Javascript Number pad(intPad)

Number.prototype.pad = function(intPad) {
  if (this<0) {
    return "-" + (this-this*2).pad(intPad);
  }/* ww w.j  a  v  a  2s. c o  m*/
  var newThis = this.toString();
  var reqPad = intPad - newThis.length;
  if (reqPad > 0) {
    return '0000000000000000'.substr(0,reqPad) + this;
  }
  return newThis;
};



PreviousNext

Related