diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-27 03:28:14 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-27 03:45:32 -0400 |
commit | f1795e628b0027aed2dc344c757167887c337bc1 (patch) | |
tree | 4fea3644081c427daf247f34327510834ce28d5e /src/commodity.cc | |
parent | 501949a364d3a26418bd59957be4015207312191 (diff) | |
download | fork-ledger-f1795e628b0027aed2dc344c757167887c337bc1.tar.gz fork-ledger-f1795e628b0027aed2dc344c757167887c337bc1.tar.bz2 fork-ledger-f1795e628b0027aed2dc344c757167887c337bc1.zip |
Fixed bugs relating to sign and rounding of costs
Diffstat (limited to 'src/commodity.cc')
-rw-r--r-- | src/commodity.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/commodity.cc b/src/commodity.cc index 6b39d711..18bafc8e 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -413,20 +413,21 @@ 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).unrounded()); + amount_t per_unit_cost = (is_per_unit ? cost : cost / amount).abs(); DEBUG("commodity.prices.add", "exchange: per-unit-cost = " << per_unit_cost); exchange(commodity, per_unit_cost, moment ? *moment : CURRENT_TIME()); cost_breakdown_t breakdown; - breakdown.final_cost = ! is_per_unit ? cost : (cost * amount).unrounded(); + breakdown.final_cost = ! is_per_unit ? cost : cost * amount; DEBUG("commodity.prices.add", "exchange: final-cost = " << breakdown.final_cost); if (current_annotation && current_annotation->price) - breakdown.basis_cost = (*current_annotation->price * amount).unrounded(); + breakdown.basis_cost + = (*current_annotation->price * amount).unrounded(); else breakdown.basis_cost = breakdown.final_cost; |