summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRafael Ascensão <rafa.almas@gmail.com>2021-09-25 23:47:08 +0100
committerMartin Michlmayr <tbm@cyrius.com>2021-09-27 13:14:17 +0800
commited5886921bcce0d1a261a37aa83bf135259b7d21 (patch)
tree1bdf9179310ed0ecd57c471403e2b3c2aaabb033 /src
parent24ba762f5cc5e13e02de54450f13ac4ccb639bee (diff)
downloadfork-ledger-ed5886921bcce0d1a261a37aa83bf135259b7d21.tar.gz
fork-ledger-ed5886921bcce0d1a261a37aa83bf135259b7d21.tar.bz2
fork-ledger-ed5886921bcce0d1a261a37aa83bf135259b7d21.zip
Fix --time-colon for negative time amounts
While the current formula works for positive numbers, negative numbers are incorrectly represented. One of the issues comes from the fact that floor(x) < x for every x. `amount_t precision` will always be a non negative number and the code that attempts to fix the issue for negative number will never run. If we truncate the number instead, the current formula works for both positive and negative numbers without making negative numbers a corner case. So let's do that. Signed-off-by: Rafael Ascensão <rafa.almas@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 6baa903c..4eacdd09 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -733,13 +733,9 @@ void amount_t::in_place_unreduce()
if (shifted) {
if (("h" == comm->symbol() || "m" == comm->symbol()) && commodity_t::time_colon_by_default) {
- amount_t floored = tmp.floored();
- amount_t precision = tmp - floored;
- if (precision < 0.0) {
- precision += 1.0;
- floored -= 1.0;
- }
- tmp = floored + (precision * (comm->smaller()->number() / 100.0));
+ double truncated = trunc(tmp.to_double());
+ double precision = tmp.to_double() - truncated;
+ tmp = truncated + (precision * (comm->smaller()->number() / 100.0));
}
*this = tmp;