# Proposal for modifying gnucash to use exact quantities

Bill Gribble grib@billgribble.com
27 Jul 2000 13:00:18 -0500

```Steven Murdoch <sjmurdoch@linuxfan.com> writes:
> Say I buy 10 shares at 123_1/64 pence each. Gnucash will represent this
> as 7873/64 pence per share so the total transaction value will be
> 78730/64 pence. My dealer will pay the seller of the shares 1231 pence,
> and I will be billed for =A312.31 as sellers round up.
> Gnucash will then remove 78730/64 pence from my share buying account and
> correctly display this as -=A312.31.
> Say I then repeat this transaction a further 6 times for some reason. I
> will be billed =A312.31 * 6 =3D =A373.86 so I will be =A386.17 in overdra=
ft.
> I enter this information into Gnucash and it removes 78730/64 * 6 from
> my account so I am 551110/64 pence in debt. Gnucash will then display
> this as -=A386.12 which is *not* the same as my bank balance.

Since your bank does transactions in integer SCU, each transaction
will be converted to the SCU-denominated amount on each transaction.
This is not a modification for display, as you imply, but an actual
change in the result of the multiplication to the correct
denomination; therefore, the summing operation is performed correctly.=20=20

Conversion from an exact result to the correct denomination is lossy
in some cases, as fractional cents get lost, which is why there are so
many options for the last argument to math operations... you want
control over whether rounding is up, down, banker's, etc.

As you correctly notice, it doesn't make sense to keep "exact" values
that aren't "exactly" what happened in the transaction; what's
important is to represent what's really going on.

Below I include the actual code for gnc_numeric.  It has several test
cases in a a main() at the end which will demonstrate what I'm talking
about.  You can compile it with something like
=20
gcc -o gnc-numeric-test `glib-config --cflags` gnc_numeric.c `glib-config=
--libs` -lm

Please keep in mind that there are several features suggested by folks
on the list that haven't been added yet, but will be soon.

Thanks,
b.g.

begin 664 gncn.tar.gz
M'XL(`+IW@#D``^T<:W/:2#*?^15]V4H6;,`(OQ(_DO/ZD;C.L5/\$WKW4W842
M8@!5A,3J8:_KDO]^W?.01@_`V.`X5TP<&S0S/=3DT]_9J9UO1=3DJ^U&0^;;5MUZ
MMIC2,!J-K:V-9XU&P]C>;.A_L6PVMIN;SQK;QCK^-(TFMC.:QN;V,V@L")]4
MB8+0]`&>]7V[,ZG=3DM/J?M*RMS*&48`7ZN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