diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-26 00:10:08 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-26 00:10:08 -0400 |
commit | 74e569e220bee08d6c9eda59b5e4021748344994 (patch) | |
tree | 6976db78d273adb515db5ff9be68c29c321d7811 /src/value.cc | |
parent | 247cf58bfa348ba104afe9328945979c4b154e46 (diff) | |
download | fork-ledger-74e569e220bee08d6c9eda59b5e4021748344994.tar.gz fork-ledger-74e569e220bee08d6c9eda59b5e4021748344994.tar.bz2 fork-ledger-74e569e220bee08d6c9eda59b5e4021748344994.zip |
Added a truncated() method for amounts and values
When an amount is truncated, it drops all of the extra precision and
becomes exactly the value would have seen were it printed.
Diffstat (limited to 'src/value.cc')
-rw-r--r-- | src/value.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/value.cc b/src/value.cc index 94bcfb20..75d09441 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1296,6 +1296,29 @@ value_t value_t::rounded() const return NULL_VALUE; } +value_t value_t::truncated() const +{ + switch (type()) { + case INTEGER: + return *this; + case AMOUNT: + return as_amount().truncated(); + case BALANCE: + return as_balance().truncated(); + case SEQUENCE: { + value_t temp; + foreach (const value_t& value, as_sequence()) + temp.push_back(value.truncated()); + return temp; + } + default: + break; + } + + throw_(value_error, _("Cannot truncate %1") << label()); + return NULL_VALUE; +} + value_t value_t::unrounded() const { switch (type()) { |