JS: Amount - handle plain numbers as arguments to ratio_human and product_human.

This commit is contained in:
Stefan Thomas
2013-02-22 12:45:27 +01:00
parent d394b074db
commit 76fd1896f8

View File

@@ -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);
}