Solved

Convert float to varchar

Posted on 2004-10-07
4
3,626 Views
Last Modified: 2012-06-22
I need to convert a float datatype to a varchar datatype.  Right now I use convert(varchar, myFloatField).  This works, however, I get the value with the exp format.  I don't want this.  If the varchar value is -1277739.244272, I don't want the converted float value of -1.27774e+006, I want the float value of  -1277739.244272.  What am I doing wrong?  

(I can't use the exp value b/c this field gets DTS'ed to Oracle...messy at best)  
0
Comment
Question by:sjeff1
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Hilaire earned 500 total points
ID: 12250050
try
cast(myfloatfield as decimal 30,10)
0
 
LVL 6

Expert Comment

by:boblah
ID: 12250098
Hi Hilaire,

you need brackets round the 30,10 like

cast(myfloatfield as decimal(30,10))

Cheers!
0
 

Author Comment

by:sjeff1
ID: 12250164
Thanks,  why does it do this?  Is there a setting to prevent this?

Thanks for the prompt attention...TH morning chaos.

sj in Colorado
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 12250244
Thks for correcting me boblah.

>>why does it do this? <<
the float datatype has many features that make it difficult to use.
some numbers can't be stored precisely due to the storage format.

eg try
select cast(4.23 as float)   --> returns 4.2300000000000004

sometimes you can lose digits due to maximum significative digits number

and the display ...


Whenever I need to do calculations on amounts or "normal" numbers (not 6.02 E 23) , I stick to decimal(digits, precision) data type.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question