On Apr 11, 2009, at 8:06 AM, Brian Downing wrote:
On current master (ca42f2b9a), Ubuntu Intrepid (with libmpfr build
from
the Jaunty package to get 2.4):
$ cat >rounding.dat <<EOF
2009/01/01 Sample
assets 134.123 FOO @ $8.88
assets 100 BAR @ $8.88
equity
EOF
Better to use <<'EOF' here.
$ ./ledger -f rounding.dat print
2009/01/01 Sample
assets 134.123 FOO @
$8.8799999999999999975
assets 100 BAR @ $8.88
equity
Bear in mind that computers are not base-10. Ledger stores the amount
of the FOO posting as 134123/1000, which is an exact representation no
matter the base. It records the total cost of the posting as
134123/1000 * 888/100.
When it finally comes time to render the amount as a decimal, the MPFR
library does the math to provide the closest value possible within the
rounding "range". The problem here is that I don't do typical
rounding for commodity prices, since you don't always want a
truncation at 2 decimal places in that case.
Long story short, what that extreme fraction means is that
0.00000000000000000025 cents is being lost due to the conversion from
decimal to binary back to decimal again. Normally you never see this
because 1) it is too small, and 2) it gets rounded away. But as I
mentioned, I don't do rounding for commodity prices.
I'll have to think about this some more, and maybe institute a policy
where prices get rounded to the normal display precision (in this case
2) plus an arbitrary constant, like 4 more decimal places.
John