AUDIT: r17457 - gnucash/trunk/src/app-utils - Don't round values that will be displayed as expressions. Save some space in fractional displays by, for example, showing "1 + 1/8" instead of "1 + 1 / 8". Simplify fractional display of values less than 1 by, for example, showing "1/3" instead of "0 + 1 / 3".

Charles Day cedayiv at cvs.gnucash.org
Thu Aug 7 15:40:15 EDT 2008


Author: cedayiv
Date: 2008-08-07 15:40:15 -0400 (Thu, 07 Aug 2008)
New Revision: 17457
Trac: http://svn.gnucash.org/trac/changeset/17457

Modified:
   gnucash/trunk/src/app-utils/gnc-ui-util.c
Log:
Don't round values that will be displayed as expressions. Save some space in fractional displays by, for example, showing "1 + 1/8" instead of "1 + 1 / 8". Simplify fractional display of values less than 1 by, for example, showing "1/3" instead of "0 + 1 / 3".
BP


Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c	2008-08-07 18:18:00 UTC (rev 17456)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c	2008-08-07 19:40:15 UTC (rev 17457)
@@ -1260,6 +1260,7 @@
   char temp_buf[128];
   gnc_numeric whole, rounding;
   int min_dp, max_dp;
+  gboolean value_is_decimal;
 
   g_return_val_if_fail (info != NULL, 0);
 
@@ -1273,6 +1274,9 @@
   /* print the absolute value */
   val = gnc_numeric_abs (val);
 
+  /* Try to print as decimal. */
+  value_is_decimal = gnc_numeric_to_decimal(&val, NULL);
+
   /* Force at least auto_decimal_places zeros */
   if (auto_decimal_enabled) {
     min_dp = MAX(auto_decimal_places, info->min_decimal_places);
@@ -1288,7 +1292,7 @@
     max_dp = 99;
 
   /* rounding? -- can only ROUND if force_fit is also true */
-  if (info->round && info->force_fit) {
+  if (value_is_decimal && info->round && info->force_fit) {
     rounding.num = 5; /* Limit the denom to 10^13 ~= 2^44, leaving max at ~524288 */
     rounding.denom = pow(10, max_dp + 1);
     val = gnc_numeric_add(val, rounding, GNC_DENOM_AUTO, GNC_DENOM_LCD);
@@ -1382,22 +1386,24 @@
 
   /* 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, print the fraction as an expression. */
+  if (!value_is_decimal)
   {
-    if (!gnc_numeric_zero_p (val))
-    {
-      val = gnc_numeric_reduce (val);
+    val = gnc_numeric_reduce (val);
 
-      if (val.denom > 0)
-          sprintf (temp_buf, " + %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT,
-                   val.num, val.denom);
-      else
-          sprintf (temp_buf, " + %" G_GINT64_FORMAT " * %" G_GINT64_FORMAT,
-                   val.num, -val.denom);
+    if (val.denom > 0)
+        sprintf (temp_buf, "%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
+                 val.num, val.denom);
+    else
+        sprintf (temp_buf, "%" G_GINT64_FORMAT " * %" G_GINT64_FORMAT,
+                 val.num, -val.denom);
 
-      strcat (buf, temp_buf);
-    }
+    if (whole.num == 0)
+      *buf = '\0';
+    else
+      strcat(buf, " + ");
+
+    strcat (buf, temp_buf);
   }
   else
   {



More information about the gnucash-changes mailing list