From 7c85fa2b3567c16a391335e3ae6c71b44b04b3b9 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Wed, 3 Jul 2002 05:59:51 +0000 Subject: [PATCH] If 'auto decimal places' is set then make sure all numbers have a decimal point in them. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7077 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/gnc-ui-util.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app-utils/gnc-ui-util.c b/src/app-utils/gnc-ui-util.c index c661783aeb..17b22b912c 100644 --- a/src/app-utils/gnc-ui-util.c +++ b/src/app-utils/gnc-ui-util.c @@ -1473,6 +1473,7 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info) { guint8 num_decimal_places = 0; char *temp_ptr = temp_buf; + int min_dp, max_dp; *temp_ptr++ = info->monetary ? lc->mon_decimal_point[0] : lc->decimal_point[0]; @@ -1491,8 +1492,16 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info) val.num = val.num - (digit * val.denom); } - /* add in needed zeros */ - while (num_decimal_places < info->min_decimal_places) + /* Force at least auto_decimal_places zeros */ + if (auto_decimal_enabled) { + min_dp = MAX(auto_decimal_places, info->min_decimal_places); + max_dp = MAX(auto_decimal_places, info->max_decimal_places); + } else { + min_dp = info->min_decimal_places; + max_dp = info->max_decimal_places; + } + + while (num_decimal_places < min_dp) { *temp_ptr++ = '0'; num_decimal_places++; @@ -1502,13 +1511,13 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info) *temp_ptr-- = '\0'; /* Here we strip off trailing decimal zeros per the argument. */ - while (*temp_ptr == '0' && num_decimal_places > info->min_decimal_places) + while (*temp_ptr == '0' && num_decimal_places > min_dp) { *temp_ptr-- = '\0'; num_decimal_places--; } - if (num_decimal_places > info->max_decimal_places) + if (num_decimal_places > max_dp) { PWARN ("max_decimal_places too small; limit %d, value %s%s", info->max_decimal_places, buf, temp_buf); @@ -2119,7 +2128,7 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result, numer *= denom; numer += fraction; } - else if (auto_decimal_enabled && !got_decimal) + else if (monetary && auto_decimal_enabled && !got_decimal) { if ((auto_decimal_places > 0) && (auto_decimal_places < 9)) {