Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3653
  • Last Modified:

Convert float to varchar

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
sjeff1
Asked:
sjeff1
  • 2
1 Solution
 
HilaireCommented:
try
cast(myfloatfield as decimal 30,10)
0
 
boblahCommented:
Hi Hilaire,

you need brackets round the 30,10 like

cast(myfloatfield as decimal(30,10))

Cheers!
0
 
sjeff1Author Commented:
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
 
HilaireCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now