# * decimal precision, balancing and display

# http://code.google.com/p/hledger/issues/detail?id=23
#
# ** 1. original test case, this should balance since price precisions do
# not affect the canonical display precisions used for display and balancing
<
2010/1/1 x
   A  55.3653 C @ 30.92189512 D
   A  -1712 D
$ hledger -f - print
2010-01-01 x
    A    55.3653 C @ 30.92189512 D
    A                      -1712 D

>= 0

# ** 2. here the price should be printed with its original precision, not
# the canonical display precision. And the inferred amount should be printed
# with the canonical precision (2 digits, inferred from the first posting).
<
2010/1/1
   a  $0.00
   a  1C @ $1.0049
   a
$ hledger -f - print --explicit
2010-01-01
    a           $0.00
    a    1C @ $1.0049
    a        $-1.0049

>= 0

# ** 3. with $'s display precision at 3 or more, this txn should not balance.
# The error message shows the difference with full precision.
<
2010/1/1
   a  1C @ $1.0049
   a  $-1.000
$ hledger -f - balance --no-total --cost --empty
>2 /should be 0 but is: \$0.0049/
>= 1

# ** 4. with $'s display precision at 2 or less, this txn should balance
<
2010/1/1
   a  1C @ $1.0049
   a  $-1.00
$ hledger -f - balance --no-total --cost --empty
                   0  a

# ** 5. avamk's 2011/1/19 example
<
2001/01/01 * ACME fund
           assets:investment:ACME     203.890 ACME @ $16.02
           equity:opening balances
$ hledger -f - balance --cost
            $3266.32  assets:investment:ACME
           $-3266.32  equity:opening balances
--------------------
                   0  

# hledger 0.14pre: precision=2, presumably from price
#            $3266.32  assets:investment:ACME
#           $-3266.32  equity:opening balances
#--------------------
#               $0.00
#
# ledger "2.6.0.90" with -s: full precision, ignores price
#          $3266.3178  assets:investment:ACME
#         $-3266.3178  equity:opening balances
#
# ledger 3: precision=0, uses default, ignores price
#               $3266  assets:investment:ACME
#              $-3266  equity:opening balances
#--------------------
#                   0

## 6. with a default commodity..
<
D $1000.0
2001/01/01 * ACME fund
           assets:investment:ACME     203.890 ACME @ $16.02
           equity:opening balances
$ hledger -f - balance --cost
             $3266.3  assets:investment:ACME
            $-3266.3  equity:opening balances
--------------------
                   0  
### hledger 0.14pre: precision=2, presumably from price, ignores D
###            $3266.32  assets:investment:ACME
###           $-3266.32  equity:opening balances
###--------------------
###               $0.00
###
### ledger "2.6.0.90" with -s: full precision, ignores price and D
###          $3266.3178  assets:investment:ACME
###         $-3266.3178  equity:opening balances
###
### ledger 3: precision=1, ignores price, observes D
###             $3266.3  assets:investment:ACME
###            $-3266.3  equity:opening balances
###--------------------
###                   0

# 
# ** 7. when there are multiple postings in the commodity being priced,
# show the averaged unit price, with precision equal to the sum of
# the max precisions of the commodities being converted (#262).
# Here the (irrational) price should be displayed with just precision 4
# (C's precision 2 + D's precision 2).
<
2015/1/1
    c    C 10.00
    c    C 11.00
    d  D -320.00
$ hledger -f- print --explicit
2015-01-01
    c    C 10.00 @ D 15.2381
    c    C 11.00 @ D 15.2381
    d              D -320.00

>= 0


# ** 8. Here the price should be displayed with precision 7
# (E's precision 4 + F's precision 3).
<
2015/1/1
    e    E 10.0000
    e    E 11
    f  F -320.000
$ hledger -f- print --explicit
2015-01-01
    e    E 10.0000 @ F 15.2380952
    e         E 11 @ F 15.2380952
    f                  F -320.000

>= 0

# ** 9. Posting amounts inferred from balance assignments also affect commodity styles. (#2091)
<
2023-01-01
  (a)        1 A
2023-01-02
  (a)              = 2.2 A
$ hledger -f- reg
2023-01-01                      (a)                          1.0 A         1.0 A
2023-01-02                      (a)                          1.2 A         2.2 A

# ** 10. print-like reports add a trailing decimal mark, when amounts have digit group marks but no decimal digits.
<
commodity 1.000, JPY

2023-01-01
  (a)                 1 JPY

2023-01-02
  (b)                 1,2 JPY

2023-01-03
  (c)             1.000 JPY

$ hledger -f - print
2023-01-01
    (a)           1 JPY

2023-01-02
    (b)         1,2 JPY

2023-01-03
    (c)      1.000, JPY

>=

# ** 11. Non-print-like reports show all amounts with consistent display precision
$ hledger -f - bal
               1 JPY  a
               1 JPY  b
           1.000 JPY  c
--------------------
           1.002 JPY  

# ** 12. csv, json and other machine-readable formats show all amounts without digit groups and with period decimal marks.
$ hledger -f - bal -O csv
"account","balance"
"a","1 JPY"
"b","1 JPY"
"c","1000 JPY"
"total","1002 JPY"
