diff --git a/src/core/amount.js b/src/core/amount.js index f2959d4d..d207df51 100644 --- a/src/core/amount.js +++ b/src/core/amount.js @@ -120,18 +120,14 @@ Amount.from_components_unsafe = function(value: Value, currency: Currency, // be sure that _is_native is set properly BEFORE calling _set_value Amount.prototype._set_value = function(value: Value) { - this._value = value.isZero() && value.isNegative() ? value.negate() : value; this._check_limits(); - }; // Returns a new value which is the absolute value of this. Amount.prototype.abs = function() { - return this._copy(this._value.abs()); - }; Amount.prototype.add = function(addend) { @@ -229,7 +225,7 @@ Amount.prototype.ratio_human = function(denom, opts) { // // To compensate, we multiply the numerator by 10^xns_precision. if (denominator._is_native) { - numerator._set_value(numerator.multiply(bi_xns_unit)); + numerator._set_value(numerator._value.multiply(bi_xns_unit)); } return numerator.divide(denominator); diff --git a/test/amount-test.js b/test/amount-test.js index fa6c3fc4..49753b17 100644 --- a/test/amount-test.js +++ b/test/amount-test.js @@ -1048,6 +1048,17 @@ describe('Amount', function() { }); describe('ratio_human', function() { + it('Divide USD by XRP', function() { + const a = Amount.from_json({ + value: '0.08161672093323858', + currency: 'USD', + issuer: 'rLFPPebckMYZf3urdomLsaqRGmQ6zHVrrK' + }); + const b = Amount.from_json('15000000'); + const c = a.ratio_human(b); + assert.deepEqual(c.to_json(), {value: '0.005441114728882572', + currency: 'USD', issuer: 'rLFPPebckMYZf3urdomLsaqRGmQ6zHVrrK'}); + }); it('Divide USD by XAU (dem)', function() { assert.strictEqual(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').ratio_human(Amount.from_json('10/015841551A748AD2C1F76FF6ECB0CCCD00000000/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'), {reference_date: 443845330 + 31535000}).to_text_full(), '201.0049931765529/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); });