how to get 2 digits after decimal point in tsql?

前端 未结 8 1062
梦如初夏
梦如初夏 2021-02-02 05:42

I am having problem to format digits in my select column.I used FORMAT but it doesn\'t work. Here is my column:

sum(cast(datediff(second, IEC.CREATE_DATE, IEC.ST         


        
8条回答
  •  暖寄归人
    2021-02-02 06:06

    Try this one -

    DECLARE @i FLOAT = 6.677756
    
    SELECT 
          ROUND(@i, 2)
        , FORMAT(@i, 'N2')
        , CAST(@i AS DECIMAL(18,2))
        , SUBSTRING(PARSENAME(CAST(@i AS VARCHAR(10)), 1), PATINDEX('%.%', CAST(@i AS VARCHAR(10))) - 1, 2)
        , FLOOR((@i - FLOOR(@i)) * 100)
    

    Output:

    ----------------------
    6,68
    6.68
    6.68
    67
    67
    

提交回复
热议问题