padding in Number


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Number.prototype.padding = function(length){
  2. return '0'.times(length-(this.toString().length)) + this.toString();
  3. };
  4.  
  5. (3).padding(3);//show:003

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.