1 /** 2 * @fileOverview Extensions/helper methods for Numbers 3 * @author <a href="http://www.bobs-bits.com">Stephen Reay</a> 4 */ 5 6 /** 7 * Convert a Number into a String padded at the beginning to the specified length 8 * @param {Number} [length=2] the length to pad the Number to 9 * @param {String} [char=0] the character to use for padding 10 * @returns {String} the Number, padded to the specified length 11 */ 12 Number.prototype.toPaddedString = function toPaddedString(length, char) { 13 length = length || 2; 14 char = char || '0'; 15 16 var that = this.toString(); 17 while (that.length < length) { 18 that = char + that; 19 } 20 21 return that; 22 }; 23