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
Solved

Convert float to varchar

Posted on 2004-10-07
4
3,631 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

839 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