Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,

I wanted to show the exponential values into actual values in sql(eg 3.43881e+007)

regards
Hymz
Posted
Updated 24-Jun-12 21:28pm
v2
Comments
Herman<T>.Instance 25-Jun-12 5:24am    
Have you read this or this

1 solution

hi,

Please try this.

Within SQL Server the max precision (or "length") of a number is 38.
So, you could use
SELECT convert(numeric(38,0),cast(@value AS float))



But you have to be careful for several reasons:
1) if you try to convert numbers with negative exponent, the conversion from above will return Zero.
2) This conversion will not give you the exact number due to internal rounding errors.
Example: '3.733241996799E+27' will return fine but '3.733241996799E+36' will be different.
3) The conversion will fail for any number larger than 10^38–1.

So, you need to decide what you're looking for:
a) get rid of the varchar column (just change to float, but still have exponential notation)
b) change it to numeric values with the risk of getting results that are slightly off (or require additional rounding routine) and the risk of not being able to convert all values or
c) maybe you have a different requirement...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900