October 15, 2007 at 12:57 pm
say you run this sql:
DECLARE @fl AS FLOAT
SET @fl = 789512385
SELECT CAST(@fl AS VARCHAR(50))
it prints out 7.89512e+008
I need to get this value converted to varchar without loosing its formatting because I need to put a float column into a varchar column, but we want the values to look like 789512385, not 7.89512e+008
I've tried using the different "styles" in the convert function, but none got me to where I need to be.
Anyone know how to handle this?
October 15, 2007 at 1:05 pm
i'm not sure why it jumps to scientific notation...wierd.
this works, it's simply a double cast/do the same with convert:
DECLARE @fl AS FLOAT
SET @fl = 789512385
SELECT cast(CAST(@fl AS bigint) AS varchar(50))
Lowell
October 15, 2007 at 1:08 pm
That works - thanks a bunch. seems like I tried that one, but I must have had something wrong:)
October 16, 2007 at 4:40 pm
The correct "casting" function should be STR.
DECLARE @fl AS FLOAT
SET @fl = 789512385
SELECT str(@fl,9,0)
* Noel
October 17, 2007 at 7:39 pm
DECLARE @fl AS FLOAT
Just change float to decimal (or numeric). Internally, floats and doubles are maintained in an entirely different format from decimals and numerics. That's why you don't get the rounding (and apparently conversion) problems with decimal/numeric.
Tomm Carr
--
Version Normal Form -- http://groups.google.com/group/vrdbms
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply