summaryrefslogtreecommitdiff
path: root/src/amount.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/amount.cc')
-rw-r--r--src/amount.cc34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/amount.cc b/src/amount.cc
index d3265bc0..8d433ad4 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -571,40 +571,40 @@ amount_t& amount_t::in_place_negate()
return *this;
}
-amount_t amount_t::round() const
+amount_t& amount_t::in_place_round()
{
if (! quantity)
throw_(amount_error, "Cannot round an uninitialized amount");
- if (! has_commodity())
- return *this;
+ if (has_commodity())
+ in_place_round(commodity().precision());
- return round(commodity().precision());
+ return *this;
}
-amount_t amount_t::round(precision_t prec) const
+amount_t& amount_t::in_place_round(precision_t prec)
{
if (! quantity)
throw_(amount_error, "Cannot round an uninitialized amount");
- amount_t t(*this);
-
- if (quantity->prec <= prec) {
- if (quantity && quantity->has_flags(BIGINT_KEEP_PREC)) {
- t._dup();
- t.quantity->drop_flags(BIGINT_KEEP_PREC);
+ if (quantity && quantity->prec <= prec) {
+ if (quantity->has_flags(BIGINT_KEEP_PREC)) {
+ _dup();
+ quantity->drop_flags(BIGINT_KEEP_PREC);
}
- return t;
+ return *this;
}
- t._dup();
+ DEBUG("amount.round", "Rounding " << *this << " to precision " << prec);
- mpz_round(MPZ(t.quantity), MPZ(t.quantity), t.quantity->prec, prec);
+ mpz_round(MPZ(quantity), MPZ(quantity), quantity->prec, prec);
- t.quantity->prec = prec;
- t.quantity->drop_flags(BIGINT_KEEP_PREC);
+ quantity->prec = prec;
+ quantity->drop_flags(BIGINT_KEEP_PREC);
- return t;
+ DEBUG("amount.round", " result = " << *this);
+
+ return *this;
}
amount_t amount_t::unround() const