Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 print value as float

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-07-02 : 08:11:16
Hi,
The select query retrieves a field which is of type float
The value returned is: 138634.4698

declare @value1 float
declare @value2 float

select
@value1 = value1,
@value2 = value2
from tblMain where ID = 1

In the table the value1 and value2 are 138634.4698 and 1865657.02 respectively.

Questions:

1- Do you know why my print statement below shows the value1 as 138634 ?
print 'value1 -->' + convert(varchar(50), @value1)

2-Do you know why my print statement below shows the value2 as 138634 ?
print 'value2 -->' + convert(varchar(50), @value2)

Thanks

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-07-02 : 12:27:12
things are floating around

declare @value1 float
declare @value2 float
declare @value3 nvarchar(50)
declare @value4 nvarchar(50)

select @value1 = 38634.4698
select @value3 = convert(decimal(10,4),@value1)
select @value2 = 1865657.02
select @value4 = convert(decimal(10,2),@value2)

print 'value1 -->' + @value3

print 'value2 -->' + @value4

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-07-04 : 07:16:34
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-04 : 18:57:40
float is an approximate decimal value so if you want decimal level accuracy go for decimal or numeric

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-07-05 : 12:08:07
sure thing

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page
   

- Advertisement -