Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CONVERT float to varchar - scientific notation 1

Status
Not open for further replies.

mwolf00

Programmer
Joined
Nov 5, 2001
Messages
4,177
Location
US
I am trying to covert float data to a varchar without having numbers over 6 digits end up in scientific notation. Any ideas?

FLOAT = 1,382,903 (commas added for clarity)
VARCHAR = 1.3829030e+006

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
I checked BOL and it implies that FLOAT is stored using scientific notation....so FLOAT would store:

1382903 as 1.3829030e+006

which is why that's how it appears as VARCHAR.

-SQLBill
 
Try this:

DECLARE @mynumber FLOAT
SET @mynumber = 1382903
SELECT CAST((CAST(@mynumber AS INT)) AS VARCHAR(10))

-SQLBill
 
Does that mean that there is no way to make if appear in "normal" notation - I need to add it to a string...

Code:
SELECT '<td><input name="billRSF' + cast(f.fieldID as varchar(2)) + '" value="' + isNull(convert(varchar(20),a.billRSF,1),'') + '" READONLY class="readOnly"></td>'
FROM ...


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Our posts crossed paths - your solution worked.

Thank you.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
BTW-The max for FLOAT is 53, but it can turn out to be a larger number than 53 characters. You might want to first CAST it to an INTEGER and then find the LENgth of the INTEGER and use that to create the length of the VARCHAR.

Just a thought and it depends on how you are going to use it. If you are populating a column, you might just want to estimate the longest FLOAT that you could have and make the VARCHAR column that length.

-SQLBill

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top