views:

911

answers:

2

Group, I am sure this is user error somehow, but I am trying to CAST a column of numbers from a float to a varchar. It works great for anything under 7 digits, but if the number is 7 digits it turns it into scientific notation or what ever they call that. For example:

440000 displays 440000 1299125 displays 1.29913e+006

It looks like it is rounding 7 digit numbers up... which I am not sure why.

I am trying to convert it because I need to concatenated it to other fields that are all VARCHAR

Any help is greatly appreciated

+2  A: 

Does this blog post answer your question?

JD
+3  A: 

Wrap your float within the str() function which, when given only one parameter, does have the side effect of dropping off everything to the right of the decimal point.

Problem:

select cast(cast(1234567890.01 as float) as varchar)

1.23457e+009

Answer without decimal:

select str(cast(1234567890.01 as float))

1234567890

Answer with decimal:

select str(cast(1234567890.01 as float),13,2)

1234567890.01
tom