Skip to content

Instantly share code, notes, and snippets.

@lucasferreira
Created September 13, 2014 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasferreira/a881606894dde5568029 to your computer and use it in GitHub Desktop.
Save lucasferreira/a881606894dde5568029 to your computer and use it in GitHub Desktop.
Fill a number or string with zeroes (pad number with [n] zeroes)
/* Autor: Lucas Ferreira - http://blog.lucasferreira.com | Usage: fz(9) or fz(100, 7) */
function fz(o, s) {
for(var s=Math.max((+s||2),(n=""+Math.abs(o)).length); n.length<s; (n="0"+n));
return (+o < 0 ? "-" : "") + n;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment