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.
Cast to decimal before casting to varchar:
declare @a as float, @b as float
select @a=1.353954 , @b=1.353956
select
CAST(CAST(@a AS DECIMAL(38,18)) as VARCHAR(40)) AS a_float_to_varchar ,
CAST(CAST(@b AS DECIMAL(38,18)) as VARCHAR(40)) AS b_float_to_varchar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With