Skip to content

Instantly share code, notes, and snippets.

@mihi-tr
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mihi-tr/87a0c7f483a4e5d4bf46 to your computer and use it in GitHub Desktop.
Save mihi-tr/87a0c7f483a4e5d4bf46 to your computer and use it in GitHub Desktop.
Zero Padding in Javascript
// 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