Skip to content

Instantly share code, notes, and snippets.

@catdad
Last active August 29, 2015 14:02
Show Gist options
  • Save catdad/f99512c378eb9b4c3f71 to your computer and use it in GitHub Desktop.
Save catdad/f99512c378eb9b4c3f71 to your computer and use it in GitHub Desktop.
/**
* Pad a number, in string format, with leading zeros.
* @param {number|string} num The number to pad
* @param {number} [size] The target length
* @returns {string} The padded number.
*/
function pad(num, size) {
size = size || 2;
var s = num + "";
while (s.length < size) s = "0" + s;
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment