Created
June 28, 2016 20:44
-
-
Save lcomino/718d0f2c33b726788760ec9bc6566b23 to your computer and use it in GitHub Desktop.
Format a number with leading zeros
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
// http://stackoverflow.com/a/11187738 | http://stackoverflow.com/users/445126/mild-fuzz | |
Number.prototype.pad = function(size) { | |
var s = String(this); | |
while (s.length < (size || 2)) {s = "0" + s;} | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment