Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert float into varchar in SQL Server without scientific notation

Tags:

sql-server

Convert float into varchar in SQL Server without scientific notation and trimming decimals.

For example:

I have the float value 1000.2324422, and then it would be converted into varchar as same 1000.2324422.

There could be any number of decimal values...the float value comes randomly.

like image 304
Sweety Avatar asked Jun 29 '11 13:06

Sweety


People also ask

How do you convert an exponential number to in SQL Server?

For SQL Server 2012+, use TRY_CONVERT(). Conversion failed when converting the varchar value '3.3733E+15' to data type int. The issue is that all values in the 'a' column return 1 when passed to the ISNUMERIC() function. Show activity on this post. This should work.

Can you use scientific notation in SQL?

That “E” means “exponent” which is easier to understand if you aren't a math geek. Truth is, SQL Server lets you use either a D or an E in scientific notation, thus making for multiple ways to confuse you.

How do I change a number to a varchar?

TO_CHAR (number) converts n to a value of VARCHAR2 datatype, using the optional number format fmt . The value n can be of type NUMBER , BINARY_FLOAT , or BINARY_DOUBLE . If you omit fmt , then n is converted to a VARCHAR2 value exactly long enough to hold its significant digits.


1 Answers

Casting or converting to VARCHAR(MAX) or anything else did not work for me using large integers (in float fields) such as 167382981, which always came out '1.67383e+008'.

What did work was STR().

like image 184
John Brooking Avatar answered Sep 20 '22 23:09

John Brooking