SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 print value as float
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1341 Posts

Posted - 07/02/2012 :  08:11:16  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 07/02/2012 :  12:27:12  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
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
Flowing Fount of Yak Knowledge

1341 Posts

Posted - 07/04/2012 :  07:16:34  Show Profile  Reply with Quote
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 07/04/2012 :  18:57:40  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 07/05/2012 :  12:08:07  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
sure thing

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000