Merge pull request #192 from geertweening/fix/amount_precision

[FIX] confusion between precision and min_precision
This commit is contained in:
Geert Weening
2014-10-26 19:21:09 -04:00
2 changed files with 25 additions and 3 deletions

View File

@@ -1120,11 +1120,12 @@ Amount.prototype.to_human = function(opts) {
}
fraction_part = '';
} else {
fraction_part = Math.round(fraction_part / Math.pow(10, fraction_part.length - opts.precision)).toString();
var precision = Math.min(opts.precision, fraction_part.length);
fraction_part = Math.round(fraction_part / Math.pow(10, fraction_part.length - precision)).toString();
// because the division above will cut off the leading 0's we have to add them back again
// XXX look for a more elegant alternative
while (fraction_part.length < opts.precision) {
while (fraction_part.length < precision) {
fraction_part = '0' + fraction_part;
}
}