[FIX] confusion between precision and min_precision

`precision` expresses precision within the provided value and won't expand it if the max expression of the value is smaller
`min_precision` will expand the value if the max expression of the value is smaller
This commit is contained in:
Geert Weening
2014-10-23 17:59:53 -07:00
parent 0527b8c981
commit 7708c64576
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;
}
}