Skip to Content.
Sympa Menu

freetds - Re: [freetds] tds_money_to_string conversion oddity

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Craig A. Berry" <craigberry AT mac.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] tds_money_to_string conversion oddity
  • Date: Sat, 06 Dec 2003 18:04:17 -0600

Craig A. Berry wrote:

/* round to two decimal places */
if (s) {
sprintf(s, "0.%02f", atof(s));
}

But before this code in the example where I encounter the problem, s is "1.0000", so that after this code, the value of s is "0.1.000000".

I think I placed too much faith in there being a reason for the exact
layout of the format string. The attached patch solves the problem by
putting the "0." where it belongs (after the percent sign).

--- src/tds/numeric.c;-0 Fri Dec 5 14:47:56 2003
+++ src/tds/numeric.c Sat Dec 6 17:47:44 2003
@@ -96,7 +96,7 @@
*s++ = '-';
i = -i;
}
- sprintf(s, "0.%02d", i);
+ sprintf(s, "%0.02d", i);
}
return s;
#else
@@ -155,7 +155,7 @@

/* round to two decimal places */
if (s) {
- sprintf(s, "0.%02f", atof(s));
+ sprintf(s, "%0.02f", atof(s));
}

return s;



Archive powered by MHonArc 2.6.24.

Top of Page