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
This commit is contained in:
David Hampton 2002-07-03 05:59:51 +00:00
parent 702d5f3529
commit 7c85fa2b35

View File

@ -1473,6 +1473,7 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info)
{ {
guint8 num_decimal_places = 0; guint8 num_decimal_places = 0;
char *temp_ptr = temp_buf; char *temp_ptr = temp_buf;
int min_dp, max_dp;
*temp_ptr++ = info->monetary ? *temp_ptr++ = info->monetary ?
lc->mon_decimal_point[0] : lc->decimal_point[0]; 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); val.num = val.num - (digit * val.denom);
} }
/* add in needed zeros */ /* Force at least auto_decimal_places zeros */
while (num_decimal_places < info->min_decimal_places) 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'; *temp_ptr++ = '0';
num_decimal_places++; num_decimal_places++;
@ -1502,13 +1511,13 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info)
*temp_ptr-- = '\0'; *temp_ptr-- = '\0';
/* Here we strip off trailing decimal zeros per the argument. */ /* 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'; *temp_ptr-- = '\0';
num_decimal_places--; 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", PWARN ("max_decimal_places too small; limit %d, value %s%s",
info->max_decimal_places, buf, temp_buf); info->max_decimal_places, buf, temp_buf);
@ -2119,7 +2128,7 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
numer *= denom; numer *= denom;
numer += fraction; 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)) if ((auto_decimal_places > 0) && (auto_decimal_places < 9))
{ {