summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2013-01-30 15:35:31 -0700
committerCraig Earls <enderw88@gmail.com>2013-01-30 15:35:31 -0700
commit0df13661686dfec66aa0d5a8dd88920e1e104fbc (patch)
treecbf9270fc8fe85d0ae67c1c1f3ab8d42296c232b /src/value.cc
parent383c341d885e1a69fc63aca2ae7db4a2ff5ff1a8 (diff)
downloadfork-ledger-0df13661686dfec66aa0d5a8dd88920e1e104fbc.tar.gz
fork-ledger-0df13661686dfec66aa0d5a8dd88920e1e104fbc.tar.bz2
fork-ledger-0df13661686dfec66aa0d5a8dd88920e1e104fbc.zip
Bug 634 Added roundto function, optimized floor and ceiling
Fixes Bug634 by adding roundto(amount, places).
Diffstat (limited to 'src/value.cc')
-rw-r--r--src/value.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/value.cc b/src/value.cc
index c57cff78..3df8f3c7 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -1612,6 +1612,27 @@ void value_t::in_place_round()
throw_(value_error, _f("Cannot set rounding for %1%") % label());
}
+void value_t::in_place_roundto(int places)
+{
+ DEBUG("amount.roundto", "=====> roundto places " << places);
+ switch (type()) {
+ case INTEGER:
+ return;
+ case AMOUNT:
+ as_amount_lval().in_place_roundto(places);
+ return;
+ case BALANCE:
+ as_balance_lval().in_place_roundto(places);
+ return;
+ case SEQUENCE:
+ foreach (value_t& value, as_sequence_lval())
+ value.in_place_roundto(places);
+ return;
+ default:
+ break;
+ }
+}
+
void value_t::in_place_truncate()
{
switch (type()) {