[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

x-rays

3/15/2007 1:34:00 PM

Hi All,

I noticed a strange behavior about Float data type.

Declaring a variable with float data type, set the decimal number 19.44228
to the variable and Print the value of the variable. It prints the following
number 19.4423. If I execute a select statement to get the value of the
variable it results 19.44228.

declare @num as float

Set @num = 19.44228
Print @num
Select @num

Is this a bug?

Thanks in advance!

Software installed:
SQL Server 2005 SP2 (Developer Edition)
3 Answers

Tibor Karaszi

3/15/2007 2:34:00 PM

0

It is not a bug. All values are in the end binary. Ass soon as you see a "human readable" format,
then some component translated the binary information into a format that we humans find more
readable. PRINT doesn't seem to follow the same rules as the way that the client tools present the
value when you do SELECT. With PRINT, the value is converted into a string at the server. With
SELECT, it is done by the client application. Another example of these differences (and evidence
that the client tool does the formatting), try below from AM and compare to SSMS:

declare @num float
Set @num = 3.1
Select @num

QA:
3.1000000000000001


SSSM:
3.1


--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/d...
http://sqlblog.com/blogs/tib...


"x-rays" <xrays@discussions.microsoft.com> wrote in message
news:725D1600-61F6-4AE3-8403-7975B05F5ADD@microsoft.com...
> Hi All,
>
> I noticed a strange behavior about Float data type.
>
> Declaring a variable with float data type, set the decimal number 19.44228
> to the variable and Print the value of the variable. It prints the following
> number 19.4423. If I execute a select statement to get the value of the
> variable it results 19.44228.
>
> declare @num as float
>
> Set @num = 19.44228
> Print @num
> Select @num
>
> Is this a bug?
>
> Thanks in advance!
>
> Software installed:
> SQL Server 2005 SP2 (Developer Edition)

x-rays

3/15/2007 3:56:00 PM

0

Hi Tibor,

Thank you for your response,

I know that PRINT converts the value in string, I thought that INSIDE SQL
Server, wouldn't be wise to see the value at "formated version".

PS: Well my brain stopped, what is AM exactly?

Thank you very much!

"Tibor Karaszi" wrote:

> It is not a bug. All values are in the end binary. Ass soon as you see a "human readable" format,
> then some component translated the binary information into a format that we humans find more
> readable. PRINT doesn't seem to follow the same rules as the way that the client tools present the
> value when you do SELECT. With PRINT, the value is converted into a string at the server. With
> SELECT, it is done by the client application. Another example of these differences (and evidence
> that the client tool does the formatting), try below from AM and compare to SSMS:
>
> declare @num float
> Set @num = 3.1
> Select @num
>
> QA:
> 3.1000000000000001
>
>
> SSSM:
> 3.1
>
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/d...
> http://sqlblog.com/blogs/tib...
>
>
> "x-rays" <xrays@discussions.microsoft.com> wrote in message
> news:725D1600-61F6-4AE3-8403-7975B05F5ADD@microsoft.com...
> > Hi All,
> >
> > I noticed a strange behavior about Float data type.
> >
> > Declaring a variable with float data type, set the decimal number 19.44228
> > to the variable and Print the value of the variable. It prints the following
> > number 19.4423. If I execute a select statement to get the value of the
> > variable it results 19.44228.
> >
> > declare @num as float
> >
> > Set @num = 19.44228
> > Print @num
> > Select @num
> >
> > Is this a bug?
> >
> > Thanks in advance!
> >
> > Software installed:
> > SQL Server 2005 SP2 (Developer Edition)
>
>

Tibor Karaszi

3/15/2007 4:11:00 PM

0

> PS: Well my brain stopped, what is AM exactly?

Sorry, that was typo. AM should have been QA... :-)

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/d...
http://sqlblog.com/blogs/tib...


"x-rays" <xrays@discussions.microsoft.com> wrote in message
news:10C98A93-3C1D-4E18-8D32-0EEAE4C40155@microsoft.com...
> Hi Tibor,
>
> Thank you for your response,
>
> I know that PRINT converts the value in string, I thought that INSIDE SQL
> Server, wouldn't be wise to see the value at "formated version".
>
> PS: Well my brain stopped, what is AM exactly?
>
> Thank you very much!
>
> "Tibor Karaszi" wrote:
>
>> It is not a bug. All values are in the end binary. Ass soon as you see a "human readable" format,
>> then some component translated the binary information into a format that we humans find more
>> readable. PRINT doesn't seem to follow the same rules as the way that the client tools present
>> the
>> value when you do SELECT. With PRINT, the value is converted into a string at the server. With
>> SELECT, it is done by the client application. Another example of these differences (and evidence
>> that the client tool does the formatting), try below from AM and compare to SSMS:
>>
>> declare @num float
>> Set @num = 3.1
>> Select @num
>>
>> QA:
>> 3.1000000000000001
>>
>>
>> SSSM:
>> 3.1
>>
>>
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/d...
>> http://sqlblog.com/blogs/tib...
>>
>>
>> "x-rays" <xrays@discussions.microsoft.com> wrote in message
>> news:725D1600-61F6-4AE3-8403-7975B05F5ADD@microsoft.com...
>> > Hi All,
>> >
>> > I noticed a strange behavior about Float data type.
>> >
>> > Declaring a variable with float data type, set the decimal number 19.44228
>> > to the variable and Print the value of the variable. It prints the following
>> > number 19.4423. If I execute a select statement to get the value of the
>> > variable it results 19.44228.
>> >
>> > declare @num as float
>> >
>> > Set @num = 19.44228
>> > Print @num
>> > Select @num
>> >
>> > Is this a bug?
>> >
>> > Thanks in advance!
>> >
>> > Software installed:
>> > SQL Server 2005 SP2 (Developer Edition)
>>
>>