Skip to content

Instantly share code, notes, and snippets.

@davidlonjon
Last active December 15, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidlonjon/5210188 to your computer and use it in GitHub Desktop.
Save davidlonjon/5210188 to your computer and use it in GitHub Desktop.
JavaScript: Pad numbers
// Taken from http://stackoverflow.com/questions/1267283/how-can-i-create-a-zerofilled-value-using-javascript
paddy = function(n, p, c) {
var pad_char = typeof c !== 'undefined' ? c : '0';
var p = typeof c !== 'undefined' ? p : 2;
var pad = new Array(1 + p).join(pad_char);
return (pad + n).slice(-pad.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment