TSQL Round up decimal number

前端 未结 4 885
庸人自扰
庸人自扰 2021-01-13 23:56

I have this number 0.581183781439, I need to round the number 0.582

I was trying with

SELECT ROUND (0.581183781439, 3)
------------------------------         


        
4条回答
  •  一个人的身影
    2021-01-14 00:27

    We can write a T-SQL function to round up for an arbitrary number of decimal places.

    CREATE FUNCTION RoundUp (@value float, @places int) RETURNS float
    AS
    BEGIN
        RETURN SELECT CEILING(@value * POWER(10, @places)) / POWER(10, @places)
    END
    GO
    
    SELECT Result = dbo.RoundUp(0.581183781439, 3)
    

    Result

    0.582

提交回复
热议问题