mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
[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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user