Last active
April 17, 2019 01:10
-
-
Save yelban/3268975bd5b8d49eb687e75f99c6bd74 to your computer and use it in GitHub Desktop.
Simple leading zeros 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
function leadingZero(n, nod) { | |
if ((nod < 1) || (n.toString().length >= nod)) { | |
return n.toString(); | |
} else { | |
return ('0'.toString().repeat(nod)+n).slice(-nod); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment