diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-27 02:15:27 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-27 02:15:27 -0400 |
commit | fbb0d2583173073e11976c7cd7e570d4829f0621 (patch) | |
tree | 7c83465d30bd45f89f82757d5f3041a9e3903f1f /src/amount.h | |
parent | ecb1ca71c12f7772d345f19b6df821da123d3b57 (diff) | |
download | fork-ledger-fbb0d2583173073e11976c7cd7e570d4829f0621.tar.gz fork-ledger-fbb0d2583173073e11976c7cd7e570d4829f0621.tar.bz2 fork-ledger-fbb0d2583173073e11976c7cd7e570d4829f0621.zip |
Gave round/unround/truncate all in_place_ variants
Diffstat (limited to 'src/amount.h')
-rw-r--r-- | src/amount.h | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/amount.h b/src/amount.h index 90f1359c..52cb2be9 100644 --- a/src/amount.h +++ b/src/amount.h @@ -320,17 +320,32 @@ public: default state of an amount, but if one has become unrounded, this sets the "keep precision" state back to false. @see set_keep_precision */ - amount_t rounded() const; + amount_t rounded() const { + amount_t temp(*this); + temp.in_place_round(); + return temp; + } + void in_place_round(); /** Yields an amount which has lost all of its extra precision, beyond what the display precision of the commodity would have printed. */ amount_t truncated() const { - return amount_t(to_string()); + amount_t temp(*this); + temp.in_place_truncate(); + return temp; } - + void in_place_truncate() { + *this = amount_t(to_string()); + } + /** Yields an amount whose display precision is never truncated, even though its commodity normally displays only rounded values. */ - amount_t unrounded() const; + amount_t unrounded() const { + amount_t temp(*this); + temp.in_place_unround(); + return temp; + } + void in_place_unround(); /** reduces a value to its most basic commodity form, for amounts that utilize "scaling commodities". For example, an amount of \c 1h |