Skip to Content.
Sympa Menu

freetds - Re: [freetds] MONEY type support??

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] MONEY type support??
  • Date: Mon, 18 Dec 2006 10:42:28 +0100


> > From: Sokol, Ryan - 244
> > Sent: Friday, December 15, 2006 1:43 PM
> >
> > I ran both of your queries through tsql and isql (unixODBC's tool)
> > on my Linux box and saw the rounding problem.
>
> I'm not sure I'd call it a "problem". It could be a feature, letting
> you not round things off to the nearest penny. "Money"
> doesn't usually
> imply fractions of a penny; if you need that, you need a
> floating point
> or exact numeric type.
>
> > What case were you
> > in to not see the rounding?
>
> I used Microsoft's osql.exe and Query Analyzer. It seems they do not
> round MONEY types when converting them to strings.
> Microsoft's isql.exe
> rounds to 2 places.
>
> I want to emphasize this is not standardized. T-SQL itself rounds to
> two positions:
>
> 1> select cast(cast(.116 as money) as varchar(30))
> 2> go
>
> ------------------------------
> 0.12
>
> One way around it, as you observed, is to convert to NUMERIC first.
>
> > Unfortunately, it looks like everything from FreeTDS in ODBC mode
> > automatically gets converted to a string.
>
> No, the driver certainly doesn't convert anything unless
> asked. Likely
> you're seeing PHP behavior, about which I don't know very much.
>

From
http://cvs.php.net/viewvc.cgi/php-src/ext/odbc/php_odbc.c?revision=1.196
&view=markup
you can see that PHP convert anything except BLOBs to SQL_C_CHAR. Our
ODBC driver convert MONEY -> SQL_C_CHAR with 2 decimal digits (like MS
one). So... it's a feature, not a bug :)

Regards
Frediano Ziglio





Archive powered by MHonArc 2.6.24.

Top of Page