JS: Allow an integer factor in Amount#product_human.

This commit is contained in:
Stefan Thomas
2013-02-13 18:32:14 +01:00
parent cd0a70565a
commit 7dd0ee6ed9

View File

@@ -380,7 +380,12 @@ Amount.prototype.ratio_human = function (denominator) {
* @return {Amount} The product. Unit will be the same as the first factor. * @return {Amount} The product. Unit will be the same as the first factor.
*/ */
Amount.prototype.product_human = function (factor) { Amount.prototype.product_human = function (factor) {
factor = Amount.from_json(factor); if ("number" === typeof factor && parseInt(factor) === factor) {
// Special handling of integer arguments
factor = Amount.from_json("" + factor + ".0");
} else {
factor = Amount.from_json(factor);
}
var product = this.multiply(factor); var product = this.multiply(factor);
@@ -436,7 +441,7 @@ Amount.prototype.issuer = function () {
Amount.prototype.multiply = function (v) { Amount.prototype.multiply = function (v) {
var result; var result;
if (this.is_zero()) { if (this.is_zero()) {
result = this.clone(); result = this.clone();
} }
else if (v.is_zero()) { else if (v.is_zero()) {