gnc_numeric: fractional displays and rounding

Charles Day cedayiv at gmail.com
Fri Jul 25 14:15:54 EDT 2008


There are a few bugs having to do with fractional display of values. I took
a look into this and found that fractional display occurs whenever the
denominator of a gnc_numeric is not an exact power of ten (10, 100, 1000,
etc.) even if the denominator is readily convertible to an exact power of
ten. For example, a gnc_numeric of 161/50 prints as "3 + 11/50" since 50 is
not an exact power of ten. However, this value is readily convertible to a
power of ten by multiplying by 2/2, giving 322/100 which prints as the more
friendly "3.22".

So my first question: Is there an existing routine which will take a
gnc_numeric and attempt to change its denominator to any exact power of ten?
I am aware of the gnc_numeric_convert() routine, but this appears to require
conversion to a specific denominator (such as 100000) rather than any power
of ten at all. If such a routine existed, unnecessary fractional display
could be avoided.

The second thing I wanted to ask about is rounding. Currently many prices
going into the price db experience rounding, and this causes bugs (such as
bug 309863.)  Does anyone know WHY prices are being rounded? I suspect that
this rounding is unnecessary and is being done just to avoid fractional
display (see above).

If there were a routine that converted denominators to any power of ten, but
only without rounding, then the price editor could use that on prices to
make as many as possible stored in a way that prints in decimal form.
Alternatively, the gnc_numeric printing routines such as xaccPrintAmount()
use this conversion purely for printing purposes; this would avoid all
unnecessary fractional display of gnc_numerics with only a small performance
hit (I say "small" because these routines do most of the work already and
just avoid the last few steps). Which way is preferred?

Finally, I have already written such a routine. I hope that I have not
reinvented the wheel...

Cheers,
Charles


More information about the gnucash-devel mailing list