Why is casting from float to varchar being rounded in SQL Server?

Viewed 31232

The following SQL,

declare @a as float, @b as float

select @a=1.353954 , @b=1.353956
select 
CAST(@a as VARCHAR(40)) AS a_float_to_varchar ,
CAST(@b as VARCHAR(40)) AS b_float_to_varchar

results in

a_float_to_varchar                       b_float_to_varchar
---------------------------------------- ----------------------------------------
1.35395                                  1.35396

based on 'float' and 'real' (Transact-SQL).

Float has a precision of 15 digits, so I am not sure why the number is being rounded when converted to varchar.

3 Answers
Related