Add Amount#invert.

This commit is contained in:
Stefan Thomas
2013-08-14 17:11:30 -07:00
parent 8640176a07
commit 1e1e70d9a6

View File

@@ -556,6 +556,21 @@ Amount.prototype.negate = function () {
return this.clone('NEGATE');
};
/**
* Invert this amount and return the new value.
*
* Creates a new Amount object as a copy of the current one (including the same
* unit (currency & issuer), inverts it (1/x) and returns the result.
*/
Amount.prototype.invert = function () {
var one = this.clone();
one._value = BigInteger.ONE;
one._offset = 0;
one._is_negative = false;
one.canonicalize();
return one.ratio_human(this);
};
/**
* Tries to correctly interpret an amount as entered by a user.
*