cast or convert a float to nvarchar?

前端 未结 7 1183
醉话见心
醉话见心 2021-02-03 22:02

I need to select from one column of datatype float and insert it in another column as nvarchar.

I tried to cast it: cast([Column_Name] as nvarchar(50))

7条回答
  •  广开言路
    2021-02-03 22:46

    Float won't convert into NVARCHAR directly, first we need to convert float into money datatype and then convert into NVARCHAR, see the examples below.

    Example1

    SELECT CAST(CAST(1234567890.1234  AS FLOAT) AS NVARCHAR(100))
    

    output

    1.23457e+009
    

    Example2

    SELECT CAST(CAST(CAST(1234567890.1234  AS FLOAT) AS MONEY) AS NVARCHAR(100))
    

    output

    1234567890.12
    

    In Example2 value is converted into float to NVARCHAR

提交回复
热议问题