I have a number in Javascript, that I know is less than 10000 and also non-negative. I want to display it as a four-digit number, with leading zeroes. Is there anything more e
This might help :
String.prototype.padLeft = function (length, character) { return new Array(length - this.length + 1).join(character || '0') + this; } var num = '12'; alert(num.padLeft(4, '0'));