how to get 2 digits after decimal point in tsql?

前端 未结 8 1064
梦如初夏
梦如初夏 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条回答
  •  猫巷女王i
    2021-02-02 06:21

    You could cast it to DECIMAL and specify the scale to be 2 digits

    decimal and numeric

    So, something like

    DECLARE @i AS FLOAT = 2
    SELECT @i / 3
    SELECT CAST(@i / 3 AS DECIMAL(18,2))
    

    SQLFiddle DEMO

    I would however recomend that this be done in the UI/Report layer, as this will cuase loss of precision.

    Formatting (in my opinion) should happen on the UI/Report/Display level.

提交回复
热议问题