Created
January 24, 2015 22:47
-
-
Save jessekinsman/9962e33f497613320695 to your computer and use it in GitHub Desktop.
Padding a one digit number in javascript
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
// One Digit returns string | |
function pad (n) { | |
return ("0" + n.toString()).slice(-2); | |
} | |
//Two digit returns string | |
function pad (n) { | |
return ("00" + n.toString()).slice(-3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is mostly used for times and so on when getting minutes from a date