Created
April 6, 2017 22:01
-
-
Save sandroweb/a395b2fc020574cf2649238c5fd8ff9d to your computer and use it in GitHub Desktop.
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 addMinDecimal(n, minDecimal) { | |
var numberArr = String(n).split(''), | |
i, | |
total = minDecimal - numberArr.length, | |
zeros = ''; | |
if (total > 0) { | |
for (i = 0; i < total; i = i + 1) { | |
zeros = zeros + '0'; | |
} | |
} | |
return zeros + numberArr.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment