gnc_numeric: fractional displays and rounding

Charles Day cedayiv at gmail.com
Wed Jul 30 20:22:01 EDT 2008


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?

Cheers,
Charles

Index: gnc-ui-util.c
===================================================================
--- gnc-ui-util.c       (revision 17429)
+++ gnc-ui-util.c       (working copy)
@@ -1382,8 +1382,9 @@

   /* at this point, buf contains the whole part of the number */

-  /* If it's not decimal, print the fraction as an expression */
-  if (!gnc_numeric_to_decimal(&val, NULL))
+  /* If it's not decimal, and we're not forcing it to become
+   * decimal, then print the fraction as an expression. */
+  if (!info->force_fit && !gnc_numeric_to_decimal(&val, NULL))
   {
     if (!gnc_numeric_zero_p (val))
     {


More information about the gnucash-devel mailing list