
Pad Number with Leading Zero in Javascript
The following function will pad number with leading zero(es). function pad(number, length) { var str = ” + number; while (str.length < length) { str = ‘0’ + str; } return str; } Some code to test the function: document.write(pad(1, 1) + ”); document.write(pad(1, 2) + ”); document.write(pad(15, 2) + ”); document.write(pad(1, 3) + ”);…