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.
| Author |
Topic |
|
kam
Starting Member
17 Posts |
Posted - 2006-03-06 : 18:25:42
|
| Being a bit troubled with trying to convert a float value in to an nvarchar datatype. I'm attempting to use:SET @text = convert(varchar, @xf)but it seems to round the number up to the closest whole number.Tried numerous combinations to see what result I get - DECLARE @text nvarchar(50), @textTwo nvarchar(50), @xf floatSET @xf = 414193.446821874SET @text = convert(varchar, @xf)SET @textTwo = convert(varchar, 414193.446821874)SELECT original = @xfSELECT typecast = @textSELECT typecastTwo = @textTwooriginal ----------------------------------------------------- 414193.44682187401(1 row(s) affected)typecast -------------------------------------------------- 414193(1 row(s) affected)typecastTwo -------------------------------------------------- 414193.446821874(1 row(s) affected)Any ideas, suggestion?cheers. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-03-06 : 18:58:04
|
| You need to add a style to:SET @text = convert(nvarchar(50), @original, styleGoesHere)since the default is 0 with float. 0 is "Six digits maximum. Use in scientific notation, when appropriate.".Style values for float are 0, 1, 2. Check out CONVERT function in SQL Server Books Online for details.Tara Kizeraka tduggan |
 |
|
|
kam
Starting Member
17 Posts |
Posted - 2006-03-07 : 19:08:35
|
| Tkizer, Thanks for your reply.Using styles results in exponential numbers, I'm trying to retrieve a decimal number in the form of a string. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-03-07 : 19:11:10
|
| You won't be able to do that if you convert directly from float to varchar. Can't you have your application put the string in the correct format?Tara Kizeraka tduggan |
 |
|
|
|
|
|
|
|