Solved

Convert float to varchar

Posted on 2004-10-07
4
3,641 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

636 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