gnc_numeric: fractional displays and rounding
Charles Day
cedayiv at gmail.com
Thu Jul 31 12:47:49 EDT 2008
On Wed, Jul 30, 2008 at 5:22 PM, Charles Day <cedayiv at gmail.com> wrote:
> Christian,
>
> You may have noticed that I have committed the new decimal conversion
> function to gnc_numeric.c (r17421) and made a few fixes based on it.
>
> However, I noticed that sometimes fractions print with weird rounding. For
> example, if the print_info settings specify rounding and force_fit, the
> fraction "1/3" could print as "0 + 200003/600000". It seems that rounding is
> applied to non-decimal numbers but force_fit is not. This doesn't make sense
> to me. Why would you do decimal rounding on something you intend to print as
> a fraction?
>
> On the other hand, if force_fit is supposed to make any value print in
> decimal form, then the following patch does that.
>
> What do you think?
>
Sorry, I just reread this email and it sounds a bit obscure. I am referring
to how gnc_numeric values get printed via the xaccPrintAmount function
(defined in src/app-utils/gnc-ui-util.c). There some settings (defined in
the GNCPrintAmountInfo type in src/app-utils/gnc-ui-util.h) that determine
the print format for any particular value. Two of these settings are "round"
and "force_fit", and both are booleans (technically, unsigned int's treated
as booleans). There is also a "max_decimal_places" setting that determines
the maximum number of digits that print after the decimal point.
Now, to demonstrate how this works currently, here's an example. Let's say
there is a decimal value of 9999/10000, a non-decimal value of 1/3, and
max_decimal_places is 3. Depending on how you set round and force_fit, you
get the following output by calling xaccPrintAmount():
round force_fit decimal non-decimal
===== ========= ======= =============
0 0 0.999 0 + 1/3
1 0 0.999 0 + 1/3 *untested; based on reading the code
0 1 0.999 0 + 1/3 *untested; based on reading the code
1 1 1.000 0 + 2003/6000 prints a poorly rounded fraction
Working this way would seem to make little sense. The first three cases
print identically, and the last doesn't work for non-decimal values. Here's
how I'm guessing it was intended to work:
round force_fit decimal non-decimal
===== ========= ======= =============
0 0 0.999 0 + 1/3
1 0 1.000 0 + 1/3
0 1 0.999 0.999
1 1 1.000 1.000
Is this correct? If so, I can readily provide a patch.
Cheers,
Charles
More information about the gnucash-devel
mailing list