Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Padding a one digit number in javascript
// 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);

This comment has been minimized.

Copy link
Owner Author

@jessekinsman jessekinsman commented Jan 24, 2015

This is mostly used for times and so on when getting minutes from a date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment