# * print command's amount styling
#
# Here's an overview of historical behaviour.
# See the tests below for examples.
#
# print shows four kinds of amount:
#  amt     - posting amount
#  cost    - posting amount's cost
#  bal     - balance assertion/assignment amount
#  balcost - balance assertion/assignment amount's cost
#
#  Which amounts does print do basic styling (eg symbol placement) on ?
#  
#  | hledger   | amt | cost | bal | balcost |
#  |-----------|-----|------|-----|---------|
#  | 1.1-1.14  | Y   | N    | N   | N       |
#  | 1.15-1.22 | Y   | N    | Y   | N       |
#  | 1.23-1.30 | Y   | Y    | Y   | N       |
#  |           |     |      |     |         |
#  | 1.31-     | Y   | Y    | Y   | Y       |
#  
#  Which kind of rounding does print do on each amount ?
#  
#  | hledger             | amt  | cost | bal  | balcost |
#  |---------------------|------|------|------|---------|
#  | 1.0-1.20            | hard | none | none | none    |
#  | 1.21-1.30           | soft | none | none | none    |
#  | 1.31                | none | none | none | none    |
#  |                     |      |      |      |         |
#  | 1.31.1              | none | none | none | none    |
#  | 1.31.1 --round=soft | soft | none | soft | none    |
#  | 1.31.1 --round=hard | hard | none | hard | none    |
#  | 1.31.1 --round=all  | hard | hard | hard | hard    |


# ** Four print style tests. In these, basic styling is applied
# to all amounts (the commodity symbol moves to the left),
# and precision styling is applied as described below.
<
; A and B styles
commodity A1000.00
commodity B1000.00

; a amounts have 1 significant digit
; b amounts have 1 significant digit and 2 zeros
; c amounts have 3 significant digits
2023-01-01
    (a)    0.1   A @ 0.1   B = 0.1   A @ 0.1   B
    (b)    0.100 A @ 0.100 B = 0.100 A @ 0.100 B
    (c)    0.123 A @ 0.123 B = 0.123 A @ 0.123 B

# ** 1. By default, print shows all amounts with original precisions
# (like 1.31)
$ hledger -f- print
2023-01-01
    (a)        A0.1 @ B0.1 = A0.1 @ B0.1
    (b)    A0.100 @ B0.100 = A0.100 @ B0.100
    (c)    A0.123 @ B0.123 = A0.123 @ B0.123

>=

# ** 2. With --round=soft, print adds/removes zeros in non-cost amounts
# (like 1.30 but more thorough, also affects balance assertion amounts,
# also does basic styling of balance assertion costs)
$ hledger -f- print --round=soft
2023-01-01
    (a)       A0.10 @ B0.1 = A0.10 @ B0.1
    (b)     A0.10 @ B0.100 = A0.10 @ B0.100
    (c)    A0.123 @ B0.123 = A0.123 @ B0.123

>=

# ** 3. With --round=hard, print rounds non-cost amounts.
$ hledger -f- print --round=hard
2023-01-01
    (a)      A0.10 @ B0.1 = A0.10 @ B0.1
    (b)    A0.10 @ B0.100 = A0.10 @ B0.100
    (c)    A0.12 @ B0.123 = A0.12 @ B0.123

>=

# ** 4. with --round=all, print rounds all amounts.
$ hledger -f- print --round=all
2023-01-01
    (a)    A0.10 @ B0.10 = A0.10 @ B0.10
    (b)    A0.10 @ B0.10 = A0.10 @ B0.10
    (c)    A0.12 @ B0.12 = A0.12 @ B0.12

>=

# ** 5. print also preserves precisions when there's an implicit conversion
# (unlike 1.30, #2079).
<
commodity A 1000.

2023-01-01
    f       A 1.5
    g       A 1.5
    c      B -3

$ hledger -f- print
2023-01-01
    f           A 1.5
    g           A 1.5
    c            B -3

>=

# ** 6. When showing digit group marks, print always shows a decimal mark as well,
# even when no decimal digits are shown.
<
decimal-mark .
2023-01-01
    (a)    1,000

$ hledger -f- print
2023-01-01
    (a)          1,000.

>=

# ** 7. print shows zeros with a commodity symbol and decimal digits when possible.
# This also means that "multi-commodity zeros" are shown more verbosely.
<
2023-01-01
    a   A 0.00
    b   B 0.00
    c

2023-01-02
    d

$ hledger -f- print -x
2023-01-01
    a          A 0.00
    b          B 0.00
    c          A 0.00
    c          B 0.00

2023-01-02
    d               0

>=

# ** Some style/precision behaviours with cost and value, with explanations as of 2023-10.

# ** 8. Costs normally don't affect display precisions,
# so why is it showing the B amounts with 4 decimal digits instead of the default 0 ?
# Summary: a's calculated cost has 4 digits, and so also must the inferred b amount.
#
# Some implementation-level details (pre-precisiongeddon, could be out of date):
#
# In journalFinalise,
#
# journalStyleAmounts infers A and B display styles and A precision 0,
# and applies the style but not the precision to the A amount.
# 
# journalBalanceTransactions infers b's amount from a's cost,
# which it calculates as 0.1234 B.
# 
# journalInferCommodityStyles infers commodity styles again,
# now inferring B precision 4 from b's amount.
# 
# entriesReport converts a's amount to cost, calculating 0.1234 B
# with journalToCost, which does not re-apply styles or precisions.
#
# print does no rounding and shows a's cost 0.1234 B and b's amount 0.1234 B.

<
2023-01-01
  a    1 A @ 0.1234 B
  b

$ hledger -f- print -x -B
2023-01-01
    a        0.1234 B
    b       -0.1234 B

>=

# ** 9. Why is it showing the B amounts with 4 decimal digits here ?
# Summary: the a value is calculated from a nullamt with 0 decimal digits,
# then re-styled again with the 4 digit B precision inferred from b's amount.
# This works out right, in this case.
#
# Details (pre-precisiongeddon, could be out of date):
#
# journalStyleAmounts infers A display style and A precision 0 from 10 A,
# and applies the style but not the precision to all A amounts.
#
# journalBalanceTransactions infers b's amount from a's cost,
# which it calculates as 0.1234 B.
# 
# journalInferCommodityStyles infers commodity styles again,
# now inferring B precision 4 from b's amount.
# 
# journalInferMarketPricesFromTransactions infers a 0.1234 B price for A.
# 
# entriesReport converts 10 A to value using that price,
# with amountValueAtDate, which calculates from nullamt (would show as B0)
# then re-applies the inferred B style (symbol on the right)
# and sets the price's (0.1234) numeric precision (4) as the display precision,
# showing 0.1234 B.
# 
# print does no rounding, and shows a's value 0.1234 B and b's amount 0.1234 B.

<
2023-01-01
  a    1 A @ 0.1234 B
  b

$ hledger -f - print --infer-market-prices -V
2023-01-01
    a        0.1234 B
    b       -0.1234 B

>=

# ** 10. What if a different style/precision is specified for B, eg more digits
# than the price ? We expect the calculated amount to have the price's precision, as above.
<
2023-01-01
  a    1 A @ 0.1234 B
  b

$ hledger -f - print --infer-market-prices -V -c '0.123456B'
2023-01-01
    a         0.1234B
    b        -0.1234B

>=

# ** 11. Printing A's value in B, using an inferred reverse market price,
# with no B amount written in the journal to infer a display precision from.
# In this case B is displayed with the default style (symbol on the left)
# and the numeric precision of the inferred price 0.5 (1 decimal  digit).
# (#2105)
<
P 2023-01-01 B 2A

2023-01-01
  a  1A
  b

$ hledger -f- print -X B
2023-01-01
    a            B0.5
    b           B-0.5

>=

# ** 12. What if the inferred reverse market price has infinite decimal digits ?
<
P 2023-01-01 B 3.00A

2023-01-01
  a  1A
  b

# That propagates to the calculated value, causing it to be displayed with the
# default fallback precision for "infinite" decimals (8).
$ hledger -f- print -X B
2023-01-01
    a     B0.33333333
    b    B-0.33333333

>=
# preferred ?
# The reverse price is given the same precision as in the forward price declaration
# it was inferred from - 2 digits in this example, and that in turn affects the
# calculated value.
#2023-01-01
#    a     B0.33
#    b    B-0.33
#
#>=

# ** 13. Value amounts with very large but not infinite precision are still shown correctly,
# eg 100 decimal digits here.
<
P 2023-01-01 A 0.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789B

2023-01-01
  (a)  1A

$ hledger -f- print -X B
2023-01-01
    (a)    0.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789B

>=
