August 8, 2015 at 1:26 pm
Comments posted to this topic are about the item Float to Varchar
Thanks,
Naveen.
Every thought is a cause and every condition an effect
August 9, 2015 at 11:55 am
Thanks for the question
Not sure if the following link provides a better explanation.
https://msdn.microsoft.com/en-us/library/ms187928.aspx
I based my answer on the part about the style which says that the default is 6 digits.
-------------------------------------------------------------------------------------------------------------------------------
When expression is float or real, style can be one of the values shown in the following table. Other values are processed as 0.
Value
Output
0 (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.
126, 128, 129
Included for legacy reasons and might be deprecated in a future release.
August 10, 2015 at 4:22 am
jan.dewettinck (8/9/2015)
Thanks for the questionNot sure if the following link provides a better explanation.
https://msdn.microsoft.com/en-us/library/ms187928.aspx
I based my answer on the part about the style which says that the default is 6 digits.
-------------------------------------------------------------------------------------------------------------------------------
When expression is float or real, style can be one of the values shown in the following table. Other values are processed as 0.
Value
Output
0 (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.
126, 128, 129
Included for legacy reasons and might be deprecated in a future release.
+1 and thanks for this short but full and easy explanation.
As I knew that the default number of digits was 6 , the answer to find was too easy.
But thanks to the Creator of this QOT as it is good to post this kind of question.
August 10, 2015 at 5:16 am
An easy one to start the week. Thanks.
August 10, 2015 at 5:30 am
jan.dewettinck (8/9/2015)
Thanks for the questionNot sure if the following link provides a better explanation.
https://msdn.microsoft.com/en-us/library/ms187928.aspx
I based my answer on the part about the style which says that the default is 6 digits.
-------------------------------------------------------------------------------------------------------------------------------
When expression is float or real, style can be one of the values shown in the following table. Other values are processed as 0.
Value
Output
0 (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.
126, 128, 129
Included for legacy reasons and might be deprecated in a future release.
+1
😎
Default style (0) will return 6 digits.
August 10, 2015 at 6:02 am
I based my answer on the part about the style which says that the default is 6 digits.
I believe this is the actual reason why we get that result. Can verify by changing a bit the excercise:
declare @f float=115627.473121036902
select convert(varchar(20), @f)
Result: 115627
---------------
Mel. 😎
August 10, 2015 at 9:36 am
August 10, 2015 at 12:10 pm
jan.dewettinck (8/9/2015)
Thanks for the questionNot sure if the following link provides a better explanation.
https://msdn.microsoft.com/en-us/library/ms187928.aspx
I based my answer on the part about the style which says that the default is 6 digits.
-------------------------------------------------------------------------------------------------------------------------------
When expression is float or real, style can be one of the values shown in the following table. Other values are processed as 0.
Value
Output
0 (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.
126, 128, 129
Included for legacy reasons and might be deprecated in a future release.
Good to know this stuff. Thanks Jan
Thanks,
Naveen.
Every thought is a cause and every condition an effect
August 10, 2015 at 12:10 pm
August 10, 2015 at 1:33 pm
Very nice - thanks, Naveen!
August 11, 2015 at 3:10 am
Nice question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
August 11, 2015 at 2:21 pm
Great question - and even more counter-intuitive than the answers usually are!
Thanks.
- webrunner
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
August 18, 2015 at 7:41 am
Nice one, good to know, thanks.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply