summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commodity.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index 67a86b87..d826feb6 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -418,11 +418,13 @@ commodity_t::exchange(const amount_t& amount,
if (commodity.annotated)
current_annotation = &as_annotated_commodity(commodity).details;
- amount_t per_unit_cost = (is_per_unit ? cost : cost / amount).abs();
+ amount_t per_unit_cost =
+ (is_per_unit || amount.is_realzero() ? cost : cost / amount).abs();
DEBUG("commodity.prices.add", "exchange: per-unit-cost = " << per_unit_cost);
- exchange(commodity, per_unit_cost, moment ? *moment : CURRENT_TIME());
+ if (! per_unit_cost.is_realzero())
+ exchange(commodity, per_unit_cost, moment ? *moment : CURRENT_TIME());
cost_breakdown_t breakdown;
breakdown.final_cost = ! is_per_unit ? cost : cost * amount;