amount showing up with 4 decimal places due to market prices #295

Closed
sitaramc opened this Issue Nov 10, 2015 · 5 comments

Projects

None yet

2 participants

@sitaramc
sitaramc commented Nov 10, 2015 edited

Hi,

When you have a market price like
P 11/09 ABCD 11.1111
and you try a "bal -V", all amounts end up being 4 decimal places.

A complete, minimal, example is at https://gist.github.com/sitaramc/77375a348d58298fb4aa

thanks!


D 1,000.00

# -- --
Y2015

P   11/09   ABCD                            11.1111
P   11/09   EFGH                            22.2222
P   11/09   IJKL                            10

# -- --
Y2015

11/09   MF number 1
    mfs:one                       ABCD 1111
    equity:opening balance

11/09   MF number 2
    mfs:two                       EFGH 2222
    equity:opening balance

11/09   MF number 3
    mfs:three                     IJKL 1000
    equity:opening balance

# running 'hledger bal -V' on this file produces the following output:

#               -71,722.1605  equity:opening balance
#                71,722.1605  mfs
#                12,344.4321    one
#                10,000.0000    three
#                49,377.7284    two
#       --------------------
#                          0

@simonmichael
Owner

http://hledger.org/manual.html#amount-display-styles says "The precisions used in a price amount ... don't affect the canonical display precision directly", but as of 0.27 market prices do affect it. And there's no easy way in general to reduce display precision once it has increased. So we have both a doc bug and new usability issue.

@simonmichael
Owner

Relates to this commit: 7192113

@simonmichael simonmichael modified the milestone: 1.0 Nov 15, 2015
@simonmichael simonmichael self-assigned this Nov 15, 2015
@simonmichael
Owner
simonmichael commented May 7, 2016 edited

My current plan for this to let commodity styles be controlled explicitly with commodity directives. This will be simpler and more predictable. The current automatic commodity style inference could be left in, or ripped out entirely, I'm not sure yet. Docs:

As of 0.xx, hledger displays all amounts
(except for price amounts, which are displayed as recorded)
in a standard style by default:

  • The commodity/currency name/symbol is on the left, with no space between it and the amount.
  • The decimal point character is period.
  • The number of decimal places displayed is two.
  • Digit groups (eg thousands) are not shown.

You can override this on a per-commodity basis using commodity directives.
Examples:

# display AAAA amounts with the symbol on the right, space-separated,
# using period as decimal point, showing four decimal places, and
# separating thousands with comma.
commodity AAAA
 format 1,000.0000 AAAA

# display indian rupees with currency name on the left,
# thousands, lakhs and crores comma-separated,
# period as decimal point, and two decimal places.
commodity INR
 format INR 9,99,99,999.00

# display commodity-less amounts with comma as decimal point and one decimal place
commodity
 format 0,0

# set the default format for all commodities: symbol on the left, no decimal places,
# separate hundreds with comma.
commodity *
 format *1,00.
 nouse

Ledger's commodity directive, http://ledger-cli.org/3.0/doc/ledger3.html#Command-Directives -> commodity :

commodity
Pre-declare commodity names. This only has an effect if --strict or --pedantic is used (see below).

commodity $
commodity CAD

The commodity directive supports several optional sub-directives, if they immediately follow the commodity directive and—if they are on successive lines—begin with whitespace:

commodity $
   note American Dollars
   format $1,000.00
   nomarket
   default

The note sub-directive associates a textual note with the commodity. At present this has no value other than documentation.

The format sub-directive gives you a way to tell Ledger how to format this commodity. In the future, using this directive will disable Ledger’s observation of other ways that commodity is used, and will provide the “canonical” representation.

The nomarket sub-directive states that the commodity’s price should never be auto-downloaded.

The default sub-directive marks this as the “default” commodity.

@sitaramc
sitaramc commented May 7, 2016

On 05/07/2016 09:29 PM, Simon Michael wrote:

My current plan for this to let commodity styles be controlled explicitly with commodity directives. This will be simpler and more predictable. The current automatic commodity style inference could be left in, or ripped out entirely, I'm not sure yet. Docs:

As of 0.xx, hledger displays all amounts
(except for price amounts, which are displayed as recorded)
in a standard style by default:

  * The commodity/currency name/symbol is on the left, with no space between it and the amount.
  * The decimal point character is period.
  * The number of decimal places displayed is two.
  * Digit groups (eg thousands) are not shown.

You can override this on a per-commodity basis using commodity directives.
Examples:

|# display AAAA amounts with the symbol on the right, space-separated, # using period as decimal point, showing four decimal places, and # separating thousands with comma. commodity AAAA format 1,000.0000 AAAA # display indian rupees with currency name on the left, # thousands, lakhs and crores comma-separated, # period as decimal point, and two decimal places. commodity INR format INR 9,99,99,999.00 # display commodity-less amounts with comma as decimal point and one decimal place commodity format 0,0 # set the default format for all commodities: symbol on the left, no decimal places, # separate hundreds with comma. commodity * format *1,00. nouse |

Ledger's commodity directive: http://ledger-cli.org/3.0/doc/ledger3.html#Command-Directives -> commodity.

sounds like a good plan! Thank you; looking forward to it!

@simonmichael simonmichael added a commit that referenced this issue May 9, 2016
@simonmichael tests for #295 8312573
@simonmichael simonmichael added a commit that referenced this issue May 9, 2016
@simonmichael journal: commodity format directive overrides inferred style (#295)
The commodity directive's format subdirective can now be used to
override the inferred style for a commodity, eg to increase or decrease
the precision. This doesn't fix the root cause of #295 but is at least a
good workaround.
9304aa1
@simonmichael
Owner
simonmichael commented May 9, 2016 edited

commodity directives can now be used to control amount formatting. I have left the traditional automatic format inference in as a fallback, for now, noting that it's not perfect and that an explicit commodity directive is the ultimate solution. Let me know of any issues.

@simonmichael simonmichael modified the milestone: post 1.0 Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment