Browse files

Merge pull request #61 from evgenius/master

money_format works incorrectly for fractions < 0.1
  • Loading branch information...
2 parents 214eb03 + 163580b commit 46e5c8b05761cbe264754e6c2e79fff16897d846 @kvz committed Dec 20, 2012
Showing with 4 additions and 1 deletion.
  1. +4 −1 functions/strings/money_format.js
View
5 functions/strings/money_format.js
@@ -120,7 +120,10 @@ function money_format (format, number) {
fraction = '';
dec_pt = '';
} else if (right < fraction.length) {
- fraction = Math.round(parseFloat(fraction.slice(0, right) + '.' + fraction.substr(right, 1), 10)) + '';
+ 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
}

0 comments on commit 46e5c8b

Please sign in to comment.