TSQL Round up decimal number

前端 未结 4 872
庸人自扰
庸人自扰 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:17

    Adding a half value and using normal round will get the correct result.

    SELECT ROUND (0.581183781439 + .0005, 3)
    

    Bonus: Subtract the half value instead, and it will round down.

    EDIT: Actually, this has the same flaw as an answer above when the value is zeros after the 3rd decimal.

提交回复
热议问题