Converting float to decimal in SQL Server 2008

后端 未结 1 2205
谎友^
谎友^ 2021-02-19 23:24

I have a view which needs to return type decimal for columns stored as float.

I can cast each column to decimal as follows:

, CAST(Field1 as decimal) Fi         


        
1条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-19 23:58

    12, 12 means no digits before the decimal separator: 12 digits in total, 12 of them being after the period.

    Use a more appropriate range, say:

    DECLARE @var FLOAT = 100
    SELECT  CAST(@var as decimal(20,12))
    

    which gives you 8 digits before the separator, or adjust it as needed.

    0 讨论(0)
提交回复
热议问题