Created
July 6, 2009 19:04
-
-
Save atesgoral/141616 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Left-pad a number with zeros so that it's at least the given | |
* number of characters long | |
* @param n The number to pad | |
* @param len The desired length | |
*/ | |
function leftPad(n, len) { | |
return (new Array(len - String(n).length + 1)).join("0").concat(n); | |
} | |
alert(leftPad(42, 6)); // Gives you "000042" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment