question

JPCOUTINHO avatar image
JPCOUTINHO asked

How to show a number in scientific notation ?

I need to know how to express a number in scientific notation by using SQL SELECT, Ex; need that the number 300 to be expressed as 3.0E+2. with one decimal place and in scientific notation DECLARE @Nr as float SET @Nr = 300 select convert(varchar(max),@Nr,2) Result is : 3.000000000000000e+002 Need it to be : 3.0E+2
sql
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Shawn_Melton avatar image Shawn_Melton commented ·
This site is primarily hosted and monitored by English speaking users, please update your post.
0 Likes 0 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
This really sounds like something that should be done at the client side, rather than at the server side... But I'm sure someone will be along to help!
0 Likes 0 ·

1 Answer

·
David Wimbush avatar image
David Wimbush answered
If you have SQL Server 2012 or later you can do this with the format() function: declare @Nr as float = 300; select format(@Nr, '0.0E+0'); You can read more about controlling the format here: [ https://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx][1] [1]: https://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JPCOUTINHO avatar image JPCOUTINHO commented ·
Excelent...simple & efective tks a lot
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.