Skip to content

Instantly share code, notes, and snippets.

@jfhernandeze
Created January 15, 2015 06:48
Show Gist options
  • Save jfhernandeze/f08952c20c045d321737 to your computer and use it in GitHub Desktop.
Save jfhernandeze/f08952c20c045d321737 to your computer and use it in GitHub Desktop.
Zerofill for javascript
function zeroFill(number, width) {
width -= number.toString().length;
if (width > 0) {
return new Array(width + (/\./.test(number) ? 2 : 1)).join('0') + number;
}
return number + ""; // always return a string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment