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 |
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2009-09-09 : 08:20:06
|
Hi all,I try to covert a float value to a VARCHAR data type but it does not convert it completely.declare @f floatset @f=rand()select @f --0.422263491766635select cast(@f as varchar)--0.422263 How can I convert it? I want the result be: 0.422263491766635 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-09 : 08:32:20
|
convert(varchar(20), convert(decimal(20,15), @f))refer to http://msdn.microsoft.com/en-us/library/ms187928.aspxquote: float and real StylesWhen expression is float or real, style can be one of the values shown in the following table. Other values are processed as 0.Value Output0 (default) - A maximum of 6 digits. Use in scientific notation, when appropriate.1 - Always 8 digits. Always use in scientific notation.2 - Always 16 digits. Always use in scientific notation.
KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-09-09 : 08:35:47
|
| try like thisdeclare @f floatset @f=rand()select @f select convert(numeric(18,16),@f)select convert(varchar(64),convert(numeric(18,16),@f)) |
 |
|
|
|
|
|