[freetds] tds_money_to_string conversion oddity
Craig A. Berry
craigberry at mac.com
Sat Dec 6 18:04:17 EST 2003
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).
-------------- next part --------------
--- 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;
More information about the FreeTDS
mailing list