Hi all,

I'm having trouble using the roundto function.  In particular, I don't 
understand the following results:

    $ ledger eval '(roundto($0.31 / 2, 2))'
    $0.16

    $ ledger eval '(roundto($0.31 / 2, 2) == $0.16) ? "equal" : "not equal"'
    not equal

    $ ledger eval '(roundto($0.31 / 2, 2) - $0.16)'
    0

    $ ledger eval '(roundto($0.31 / 2, 2) - $0.16 == 0) ? "equal" : "not equal"'
    not equal

    $ ledger eval '(roundto($0.31 / 2, 2) - $0.16 == $0.00) ? "equal" : "not 
equal"'
    not equal

I tried adding --unround, but it didn't help.  Can someone shed light on this?

This comes up in the following context.  I have a ledger file like this:

------------------------------------------------------------------------
2018-01-01 * Purchase
    Merchant                   $0.31
    B       (roundto(-$0.31 / 2, 2))
    A1                        -$0.08
    A2

eval print("A1: " + account("A1").total)
eval print("A2: " + account("A2").total)
check (account("A1").total == account("A2").total)
------------------------------------------------------------------------

Running ledger -f test1.ledger produces this:

    $ ledger -f expenses.ledger --unround bal
    A1: $-0.08
    A2: $-0.08
    Warning: "test.ledger", line 9: Check failed: (account("A1").total == 
account("A2").total)
                  $-0.08  A1
                  $-0.08  A2
                  $-0.15  B
                   $0.31  Merchant
    --------------------
                       0

I don't understand why the check fails, as it says right there in the log that 
the totals of both A1 and A2 are $-0.08.
To try to make sense of this, I modified the file, adding -0.08 explicitly on 
the A2 line:

------------------------------------------------------------------------
2018-01-01 * Purchase
    Merchant                   $0.31
    B       (roundto(-$0.31 / 2, 2))
    A1                        -$0.08
    A2                        -$0.08

eval print("A1: " + account("A1").total)
eval print("A2: " + account("A2").total)
check (account("A1").total == account("A2").total)
------------------------------------------------------------------------

Now the check passes, and the output is the same except for one tiny 
difference: the last (total) line says $0.00 instead of 0.

    A1: $-0.08
    A2: $-0.08
                  $-0.08  A1
                  $-0.08  A2
                  $-0.15  B
                   $0.31  Merchant
    --------------------
                   $0.00

I get very similar results with different numbers:

------------------------------------------------------------------------
2018-01-01 * Purchase
    Merchant                   $0.67
    B       (roundto(-$0.67 / 2, 2))
    A1                        -$0.17
    A2

eval print("A1: " + account("A1").total)
eval print("A2: " + account("A2").total)
check (account("A1").total == account("A2").total)
------------------------------------------------------------------------

…but here if I add the A2 amount explicitly (-$0.17) the total shows up as 
$-0.00 in the balance sheet:

    A1: $-0.17
    A2: $-0.17
                  $-0.17  A1
                  $-0.17  A2
                  $-0.33  B
                   $0.67  Merchant
    --------------------
                  $-0.00

Can someone help me make sense of this?  Thanks!
Clément.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to