Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Float to Varchar in SQL

I am doing this

declare @num float = 7708369000

select  @num as [float], 
    convert(varchar, @num) as [varchar]

it gives me this

float                  varchar
---------------------- ------------------------------
7708369000             7.70837e+009

But I want this

float                  varchar
---------------------- ------------------------------
7708369000             7708369000

Please help.

like image 362
yogi Avatar asked Jul 20 '13 09:07

yogi


People also ask

Can we convert varchar to float in SQL?

If you are planning to convert varchar to float you should know that these two data types are not compatible with each other.

Can we convert float to int in SQL?

Convert Float to Int In this example, we will convert a float data type to integer. In the following query, we will declare a variable that data type is float and then we will use the SQL CONVERT function in order to convert float value to integer so for that we will perform data converting operation.

Can we convert int to varchar in SQL?

CAST Function to convert int to string In this example, we are converting the OrderQty which is an integer into varchar with SELECT CAST syntax.


1 Answers

convert it to decimal first,

CAST(CAST(@num AS DECIMAL(20)) AS VARCHAR(20))
  • SQLFiddle Demo
like image 91
John Woo Avatar answered Oct 03 '22 23:10

John Woo