Skip to content

Instantly share code, notes, and snippets.

@d-simon
Created March 7, 2014 00:42
Show Gist options
  • Save d-simon/9402826 to your computer and use it in GitHub Desktop.
Save d-simon/9402826 to your computer and use it in GitHub Desktop.
String Padding / Leading Zeros
function pad (n, width, z) {
z = z || '0';
n = n + '';
while (n.length < width) { n = z + n; }
return n;
}
function padString (str, width, paddingStr) {
paddingStr = paddingStr || '0';
str = str + '';
while (str.length < width) { str = paddingStr + str; }
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment