Created
June 3, 2011 23:20
-
-
Save migimunz/1007341 to your computer and use it in GitHub Desktop.
Pad numbers with leading zeros
This file contains hidden or 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
//for that guy on #javascript | |
function paddedNumber(n, places) | |
{ | |
var strn = n.toString(); | |
var zerosToAdd = places-strn.length; | |
if(places !== undefined && zerosToAdd > 0) | |
while(zerosToAdd--) | |
strn = "0"+strn; | |
return strn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment