r17539 - gnucash/branches/2.2/src/app-utils - [r17457, r17533] Don't round values that will be displayed as expressions
Andreas Köhler
andi5 at cvs.gnucash.org
Wed Sep 17 11:12:56 EDT 2008
Author: andi5
Date: 2008-09-17 11:12:56 -0400 (Wed, 17 Sep 2008)
New Revision: 17539
Trac: http://svn.gnucash.org/trac/changeset/17539
Modified:
gnucash/branches/2.2/src/app-utils/gnc-ui-util.c
Log:
[r17457,r17533] 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". When printing negative
quotients, use a minus between the integer and fraction part, e.g. "-1 - 1/3"
instead of "-1 + 1/3" for -4/3.
Committed by cedayiv.
Modified: gnucash/branches/2.2/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/branches/2.2/src/app-utils/gnc-ui-util.c 2008-09-17 14:50:33 UTC (rev 17538)
+++ gnucash/branches/2.2/src/app-utils/gnc-ui-util.c 2008-09-17 15:12:56 UTC (rev 17539)
@@ -1260,6 +1260,7 @@
char temp_buf[128];
gnc_numeric whole, rounding;
int min_dp, max_dp;
+ gboolean value_is_negative, value_is_decimal;
g_return_val_if_fail (info != NULL, 0);
@@ -1270,9 +1271,13 @@
return 0;
}
- /* print the absolute value */
+ /* Print the absolute value, but remember negativity */
+ value_is_negative = gnc_numeric_negative_p (val);
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 +1293,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 +1387,26 @@
/* 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 if (value_is_negative)
+ strcat(buf, " - ");
+ else
+ strcat(buf, " + ");
+
+ strcat (buf, temp_buf);
}
else
{
More information about the gnucash-changes
mailing list