Round in MS SQL on 0.05 or 0.00

前端 未结 2 1333
独厮守ぢ
独厮守ぢ 2021-01-27 09:11

Hello I am coming from Bosnia and Herzegovina and in our county the smallest note bill is 0.05, Now the government pushing us to our retrial prices rounding on 0.05 or at 0.00

2条回答
  •  孤独总比滥情好
    2021-01-27 09:49

    Thanks to marc_s, i changed to money datatype.

    float vs decimal vs money datatype article and flowchart

    ALTER FUNCTION dbo.ufnRound (@number money)
    RETURNS money
    AS
    BEGIN
        RETURN FLOOR(@number*20) / 20
    END
    GO
    SELECT dbo.ufnRound (1.22), dbo.ufnRound (1.23), dbo.ufnRound (1.27), dbo.ufnRound (1.28)
    
    -- gives    1.2    1.2   1.25   1.25
    

提交回复
热议问题