Last active
August 29, 2015 14:05
-
-
Save mihi-tr/87a0c7f483a4e5d4bf46 to your computer and use it in GitHub Desktop.
Zero Padding in Javascript
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
// Zero Pad a number in Javascript | |
// Takes e.g. zp(42,5) -> "00042" | |
var zp = function(n,c) { | |
var s = String(n); | |
if (s.length< c) { return zp("0" + n,c) } | |
else { return s } }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment