Skip to content

Instantly share code, notes, and snippets.

@sandroweb
Created April 6, 2017 22:01
Show Gist options
  • Save sandroweb/a395b2fc020574cf2649238c5fd8ff9d to your computer and use it in GitHub Desktop.
Save sandroweb/a395b2fc020574cf2649238c5fd8ff9d to your computer and use it in GitHub Desktop.
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