Skip to content

Commit

Permalink
Fixed incorrect fraction formatting in money_format
Browse files Browse the repository at this point in the history
The function worked incorrectly when the length of the fraction was less than frac_digits.

For instance, for frac_digits=2 the function returned:
money_format("%!i", 31.011); // 31.1
money_format("%!i", 31.01);  // 31.01
money_format("%!i", 31.009); // 31.1
  • Loading branch information
evgenius committed Dec 20, 2012
1 parent a75e2b0 commit 163580b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions functions/strings/money_format.js
Expand Up @@ -121,6 +121,9 @@ function money_format (format, number) {
dec_pt = '';
} else if (right < fraction.length) {
fraction = Math.round(parseFloat(fraction.slice(0, right) + '.' + fraction.substr(right, 1))) + '';
if (right > fraction.length) {
fraction = new Array(right - fraction.length + 1).join('0') + fraction; // prepend with 0's
}
} else if (right > fraction.length) {
fraction += new Array(right - fraction.length + 1).join('0'); // pad with 0's
}
Expand Down

0 comments on commit 163580b

Please sign in to comment.