> On Feb 9, 2025, at 17:32, Bo Buckley <topherbuck...@gmail.com> wrote:
> @John Ralls, would you be able to point to where in the codebase this is
> handled (i.e. where the Exchange Rate from the Transfer Funds Dialog is
> taken and how the Price Database entry Price is calculated?) I'd understand
> a lot better seeing the code. Otherwise I'm lost on why this has to be left
> as a known rounding error and cannot be handled some other way.
> 
There is no one place.  The price database is implemented in 
libgnucash/engine/commodity.cpp. The transfer dialog, of which the exchange 
rate section is a part, is in gnucash/gnome-utils/dialog-transfer.c. 
Transaction balancing is in libgnucash/engine, with pieces of it in 
Transaction.cpp, Split.cpp, and Scrub.cpp. IIRC transaction currency selection 
happens somewhere in gnucash/register/ledger-core/ but I don’t know offhand 
which file.

For the rest, you need to understand that the price database entry is a record 
of the last price retrieved or calculated on a particular day. (That’s not 
quite true, but let’s not digress into why not, it’s not important for the 
discussion at hand.

Each split has an amount of and a value. I explained what those are in my 
previous letter. They don’t have an explicit price.

Perhaps an example will help. You postulated an exchange rate of $0.66/100¥. 
Suppose you have two splits, one for 175¥ and one for 270¥.  The first one is 
$1.155, but there’s no such thing as half-pennies in US currency so it gets 
rounded to $1.16. The second is 1.782 and is rounded to $1.78. The *stored 
numbers* for the first split are 175¥ (amount) and $1.16 (value), *implying* a 
price of 116/17500 or ~.006685714285714… $/¥, The second split stores an amount 
of 270 and a value of 1.78, *implying* a price of 178/27000 or ~.006592595…. 
(GnuCash uses the exact rational number internally; decimals are used only for 
display.) 

I said “implying” because while one of those prices might get stored in the 
price database it’s quite possible that neither will or that the price in the 
price database will get overwritten later.

GnuCash must work this way in order for transactions, accounts, and the book to 
balance and stay balanced. The price database is there to calculate values for 
reports and the Accounts page, but reports have an option to calculate a 
average cost from individual splits, and that option is the only one that will 
allow the Trial Balance report to balance.

Regards,
John Ralls

_______________________________________________
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.

Reply via email to