Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hledger close prints ambiguous amounts #1137

Closed
maralorn opened this issue Nov 27, 2019 · 3 comments
Labels

Comments

@maralorn
Copy link
Contributor

@maralorn maralorn commented Nov 27, 2019

hledger close prints (for the commodity 1.000,00€) integer values without cent values.

$ cat bug.hledger
2019-12-31 test
  a  1.000,00€
  b     10,05€
  c

$ hledger -f bug.hledger close
2019/11/27 closing balances
    a                               -1.000€ = 0€
    b                               -10,05€ = 0€
    c                             1.010,05€ = 0€
    equity:closing balances               0

2019/11/28 opening balances
    a                                1.000€ = 1.000€
    b                                10,05€ = 10,05€
    c                            -1.010,05€ = -1.010,05€
    equity:opening balances               0

As the hledger manual says

Note, a number containing a single group mark and no decimal mark is ambiguous. Are these group marks or decimal marks ?

1,000
1.000

hledger will treat them both as decimal marks by default (cf #793).

So my understanding is that it should be

    a                                1.000,00€ = 1.000,00€

to prevent ambiguities.

I think this is really a bug because of this:

$ hledger -f bug.hledger close | hledger -f- print
hledger: "-" (lines 1-5)
could not balance this transaction (real postings are off by 999.000€)
2019/11/27 closing balances
    a                               -1.000€ = 0.000€
    b                              -10.050€ = 0.000€
    c                            1.010.050€ = 0.000€
    equity:closing balances               0

I am on hledger 1.15.2 on nixos stable (19.09).

@maralorn maralorn added the A BUG label Nov 27, 2019
@simonmichael simonmichael added the close label Nov 28, 2019
@simonmichael

This comment has been minimized.

Copy link
Owner

@simonmichael simonmichael commented Nov 30, 2019

Thanks for the report. In your example:

2019-12-31 test
  a  1.000,00€
  b     10,05€
  c

the comma is parsed as a decimal mark in both amounts (correct). But close elides the first amount's decimal digits in the output:

$ hledger close --closing
2019/11/28 closing balances
    a                               -1.000€ = 0€
    b                               -10,05€ = 0€
    c                             1.010,05€ = 0€
    equity:closing balances               0

It does it even if you add a commodity directive to set the display style:

commodity 1.000,00€
2019-12-31 test
  a  1.000,00€
  b     10,05€
  c
$ hledger close --closing
2019/11/28 closing balances
    a                               -1.000€ = 0€
    b                               -10,05€ = 0€
    c                             1.010,05€ = 0€
    equity:closing balances               0

..which it shouldn't. print shows it correctly, with or without the directive:

$ hledger print
2019/12/31 test
    a       1.000,00€
    b          10,05€
    c

This -1.000€ amount is what causes the second print to fail at balancing the transaction, since the single period is parsed as a decimal mark. Unless you add a commodity directive to the second print's input (and the -I flag, since we need to ignore the assertions in this small example):

$ (echo "commodity 1.000,00€"; hledger close --closing) | hledger -f- print -I
2019/11/28 closing balances
    a                            -1.000,00€ = 0,00€
    b                               -10,05€ = 0,00€
    c                             1.010,05€ = 0,00€
    equity:closing balances               0

The close output for your example should be:

$ hledger close
2019/11/28 closing balances
    a                            -1.000,00€ = 0€
    b                               -10,05€ = 0€
    c                             1.010,05€ = 0€
    equity:closing balances               0

2019/11/29 opening balances
    a                             1.000,00€ = 1.000€
    b                                10,05€ = 10,05€
    c                            -1.010,05€ = -1.010,05€
    equity:opening balances               0

Ie with the ,00 in both a amounts. As you clearly said. :)

@maralorn

This comment has been minimized.

Copy link
Contributor Author

@maralorn maralorn commented Nov 30, 2019

Yeah, exactly. I used exactly that commodity workaround.

@maralorn

This comment has been minimized.

Copy link
Contributor Author

@maralorn maralorn commented Dec 1, 2019

Wow. That was quick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.