Home Forums SQL Server 7,2000 T-SQL Problem in converting float to varchar RE: Problem in converting float to varchar

  • aravind (10/21/2008)


    The following query truncates the decimal characters when we convert it to varchar.

    declare @d float

    declare @d1 float

    select @d = 34343.454

    select @d1 = 676.1566545

    select cast (@d as varchar(50)) + CHAR (9) + cast (@d1 as varchar(50))

    ouput:

    34343.5 676.157

    but the required output is:

    34343.454 676.1566545

    Can anyone help to find a best solution for this ?

    Thanks in advance.

    declare @d float

    declare @d1 float

    select @d = '34343.454'

    select @d1 = 676.1566545

    select cast(cast (@d as decimal(12,3)) as varchar(20)) + CHAR (9) + cast(cast (@d1 as decimal(12,3)) as varchar(20))


    Madhivanan

    Failing to plan is Planning to fail