Solved

Convert float to varchar

Posted on 2004-10-07
4
3,622 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
Comment Utility
try
cast(myfloatfield as decimal 30,10)
0
 
LVL 6

Expert Comment

by:boblah
Comment Utility
Hi Hilaire,

you need brackets round the 30,10 like

cast(myfloatfield as decimal(30,10))

Cheers!
0
 

Author Comment

by:sjeff1
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Truncate vs Delete 63 86
Company name change requiring domain change 5 60
Need Counts 11 39
SQL Split character from numbers 3 15
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now