Created
March 16, 2016 13:33
-
-
Save grefel/42e014d3309027347734 to your computer and use it in GitHub Desktop.
Pad a number
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
function pad (number, length, fill) { | |
if (fill === undefined) fill = "0"; | |
var str = '' + number; | |
while (str.length < length) { | |
str = fill + str; | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment