Skip to content

Instantly share code, notes, and snippets.

@migimunz
Created June 3, 2011 23:20
Show Gist options
  • Save migimunz/1007341 to your computer and use it in GitHub Desktop.
Save migimunz/1007341 to your computer and use it in GitHub Desktop.
Pad numbers with leading zeros
//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