Last active
December 15, 2015 05:39
-
-
Save davidlonjon/5210188 to your computer and use it in GitHub Desktop.
JavaScript: Pad numbers
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
// Taken from http://stackoverflow.com/questions/1267283/how-can-i-create-a-zerofilled-value-using-javascript | |
paddy = function(n, p, c) { | |
var pad_char = typeof c !== 'undefined' ? c : '0'; | |
var p = typeof c !== 'undefined' ? p : 2; | |
var pad = new Array(1 + p).join(pad_char); | |
return (pad + n).slice(-pad.length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment