Last active
August 29, 2015 14:02
-
-
Save catdad/f99512c378eb9b4c3f71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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