Last active
August 29, 2015 14:22
-
-
Save emmgfx/5fb1ab747e9f643e5dfd to your computer and use it in GitHub Desktop.
Javascript number pad
This file contains 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
Number.prototype.pad = function(size) { | |
var s = String(this); | |
while (s.length < (size || 2)) {s = "0" + s;} | |
return s; | |
} | |
// Examples: | |
var i = 1; | |
i.pad(); //returns "01" | |
i.pad(3); //returns "001" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment