Get the number of digits after the decimal point of a float (with or without decimal part)

前端 未结 6 1610
走了就别回头了
走了就别回头了 2020-12-18 16:45

I have following list of Amount (float) in my table.

Amount
123
123.1
123.0123
123.789456

How can i get the number of digits a

6条回答
  •  情歌与酒
    2020-12-18 17:19

    You can do It in following:

    QUERY

    SELECT Amount, 
           CASE WHEN FLOOR(Amount) <> CEILING(Amount) THEN LEN(CONVERT(INT,CONVERT(FLOAT,REVERSE(CONVERT(VARCHAR(50), Amount, 128))))) ELSE 0 END AS Result
    FROM YourTable
    

    OUPUT

    Amount      Result
    123         0
    123,1       1
    123,0123    4
    123,789456  6
    

提交回复
热议问题