mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-01 09:35:48 +00:00
JS: Amount - handle plain numbers as arguments to ratio_human and product_human.
This commit is contained in:
@@ -349,6 +349,13 @@ Amount.prototype.divide = function (d) {
|
||||
* @return {Amount} The resulting ratio. Unit will be the same as numerator.
|
||||
*/
|
||||
Amount.prototype.ratio_human = function (denominator) {
|
||||
if ("number" === typeof denominator && parseInt(denominator) === denominator) {
|
||||
// Special handling of integer arguments
|
||||
denominator = Amount.from_json("" + denominator + ".0");
|
||||
} else {
|
||||
denominator = Amount.from_json(denominator);
|
||||
}
|
||||
|
||||
var numerator = this;
|
||||
denominator = Amount.from_json(denominator);
|
||||
|
||||
@@ -581,6 +588,9 @@ Amount.prototype.parse_json = function (j) {
|
||||
this._issuer = new UInt160();
|
||||
}
|
||||
}
|
||||
else if ('number' === typeof j) {
|
||||
this.parse_json(""+j);
|
||||
}
|
||||
else if ('object' === typeof j && j instanceof Amount) {
|
||||
j.copyTo(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user