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

default commodity (D) directive does not limit decimal places #1187

Closed
Simaex opened this issue Feb 10, 2020 · 5 comments
Closed

default commodity (D) directive does not limit decimal places #1187

Simaex opened this issue Feb 10, 2020 · 5 comments
Labels

Comments

@Simaex
Copy link

@Simaex Simaex commented Feb 10, 2020

I am experiencing issue. I have set precision to one decimal using journal-wide commodity directive

; commodity-less amounts should be treated as dollars
; (and displayed with symbol on the left, thousands separators and one decimal place)
D $1,000.0
; commodity EXAMPLEAMOUNT
; display EUR amounts with the symbol on the right, space-separated,
; using period as decimal point, with oner decimal place, and
; separating thousands with comma.
commodity 1,000.0 EUR

This journal-wide directive is setting report and hledger-web display precision to one decimal as it was expected.
but if I enter commodity value in any of supported formats:
P 2020/1/31 EUR 1.1034
P 2020/1/31 EUR 1.1034$
P 2020/1/31 EUR $1.1034
results in 4 decimals in reports and hledger-web interface that was not intended no convenient.
display precision in reports and hledger-web is changed according to number of decimals used in statement. For example if I change to 6 decimals
P 2020/1/31 EUR 1.103374
Reports and hledger-web interface get 6 decimals

Please let me know: is it an intended behaviour or do I miss something obvious.

Thank you for helping to make hledger better!

Things that can help us resolve your issue faster:

  • A small reproducible example

D $1,000.0
commodity 1,000.0 EUR

This is setting decimal precision to proper 1 digit
D $1,000.0
commodity 1,000.0 EUR
P 2020/1/31 EUR 1.1034

This will change display precision to 4 decimals resulting in unnecessary clatter in journal and reports.

@Simaex Simaex added the A BUG label Feb 10, 2020
@Simaex

This comment has been minimized.

Copy link
Author

@Simaex Simaex commented Feb 11, 2020

Example journal with precision settings
D $1,000.0
commodity 1,000.0 EUR
2020/01/28 Correcting transactions From Cash to PE
Assets:Cash 62
Assets:PE EUR -56
Expenses:Trading EUR 56
Expenses:Trading

Example report with proper output precision:
alex@banach:/var/lib/hledger$ hledger bs -f test.journal
Balance Sheet 2020/01/28

         ||       2020/01/28

=============++==================
Assets ||
-------------++------------------
Assets || $62.0, -56.0 EUR
Cash || $62.0
PE || -56.0 EUR
-------------++------------------
|| $62.0, -56.0 EUR
=============++==================
Liabilities ||
-------------++------------------
-------------++------------------
||
=============++==================
Net: || $62.0, -56.0 EUR

Example journal with commodity price
alex@banach:/var/lib/hledger$ cat test.journal
D $1,000.0
commodity 1,000.0 EUR
2020/01/28 Correcting transactions From Cash to PE
Assets:Cash 62
Assets:PE EUR -56
Expenses:Trading EUR 56
Expenses:Trading

P 2020/1/31 EUR 1.1034

Example report with excessive precision due to commodity price
alex@banach:/var/lib/hledger$ hledger bs -f test.journal
Balance Sheet 2020/01/28

         ||          2020/01/28

=============++=====================
Assets ||
-------------++---------------------
Assets || $62.0000, -56.0 EUR
Cash || $62.0000
PE || -56.0 EUR
-------------++---------------------
|| $62.0000, -56.0 EUR
=============++=====================
Liabilities ||
-------------++---------------------
-------------++---------------------
||
=============++=====================
Net: || $62.0000, -56.0 EUR

@simonmichael

This comment has been minimized.

Copy link
Owner

@simonmichael simonmichael commented Feb 11, 2020

Thanks for the reproducible example. You can enclose things in triple-backtick lines for better formatting, eg:

```
literal
block
```

I think you have pointed out a bug here. The doc and example at https://hledger.org/journal.html#default-commodity implies that D sets the commodity's display format, including the number of decimal places. It does set most aspects of the display format, and it can increase the number of decimal places, but it can't limit them. (It has the same effect as an ordinary posting amount.) I'll fix the doc or the behaviour in some way. As a workaround, add a full commodity directive for the currency in question, eg:

D $1,000.0
commodity $1,000.0
commodity 1,000.0 EUR

2020/01/28 Correcting transactions From Cash to PE
    Assets:Cash                                   62
    Assets:PE                                EUR -56
    Expenses:Trading                          EUR 56
    Expenses:Trading

P 2020/1/31 EUR 1.1034
$ hledger print
2020-01-28 Correcting transactions From Cash to PE
    Assets:Cash                $62.0
    Assets:PE              -56.0 EUR
    Expenses:Trading        56.0 EUR
    Expenses:Trading

simonmichael added a commit that referenced this issue Feb 11, 2020
Stop exporting journalAmounts, overJournalAmounts, traverseJournalAmounts.
Rename journalAmounts helper to journalStyleInfluencingAmounts.

D directives are now a little better at influencing amount
canonicalisation, eg in the updated test case.
simonmichael added a commit that referenced this issue Feb 11, 2020
D directives are now fully equivalent to commodity directives for
setting a commodity's display style. (Previously it was equivalent to
a posting amount, so it couldn't limit the number of decimal places.)
When both kinds of directive exist, commodity directives take precedence.
When there are multiple D directives in the journal, only the last one
affects display style.
simonmichael added a commit that referenced this issue Feb 11, 2020
simonmichael added a commit that referenced this issue Feb 11, 2020
@Simaex

This comment has been minimized.

Copy link
Author

@Simaex Simaex commented Feb 11, 2020

Thanks a lot!
The workaround looks good to me.

simonmichael added a commit that referenced this issue Feb 11, 2020
simonmichael added a commit that referenced this issue Feb 11, 2020
…1187)

Drop occasional use of "display format", prefer "display style".

[ci skip]
simonmichael added a commit that referenced this issue Feb 11, 2020
[ci skip]
@simonmichael

This comment has been minimized.

Copy link
Owner

@simonmichael simonmichael commented Feb 11, 2020

Thanks for the report. https://hledger.org/journal.html#default-commodity is up to date.

@simonmichael

This comment has been minimized.

Copy link
Owner

@simonmichael simonmichael commented Feb 11, 2020

(To be clear: I fixed D so that it can limit the number of decimal places, just like a commodity directive.)

@simonmichael simonmichael changed the title Precision display issue default commodity (D) directive does not limit decimal places Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.