Skip to content

Instantly share code, notes, and snippets.

@AlexMihov
Forked from d-simon/string_padding.js
Created April 18, 2014 20:12
Show Gist options
  • Save AlexMihov/11062355 to your computer and use it in GitHub Desktop.
Save AlexMihov/11062355 to your computer and use it in GitHub Desktop.
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