summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-26 00:10:08 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-26 00:10:08 -0400
commit74e569e220bee08d6c9eda59b5e4021748344994 (patch)
tree6976db78d273adb515db5ff9be68c29c321d7811 /src/value.cc
parent247cf58bfa348ba104afe9328945979c4b154e46 (diff)
downloadfork-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.cc23
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()) {