Reputation: 143
Can some one explain me why the results of LEFT are different? For:
Declare @f as float
set @f = 40456510.
select LEFT(cast(@f as float), LEN(4045.)), LEFT(404565., LEN(4045.))
I got:
|
------------
4.04 | 4045
Is there a default cast which causes this? Fiddle SQL
Upvotes: 2
Views: 71
Reputation: 22733
When you call LEFT(...)
on the FLOAT
value you are converting it to a string representation of the number as it's a string function. If you convert the value to a varchar
for example, you'll see what the output is:
SELECT CAST(CAST(@f as float) AS VARCHAR(100))
You get: '4.04565e+007'
So the first 4 characters of that are: '4.04'
Upvotes: 3
Reputation: 146499
The first one is taking the left 4 characters of the exponential representation. Why I don't know.
You are applying a string function [Left()] to a float variable.
Upvotes: 0