CHF Rounding in MSSQL – CHF Runden in MSSQL

In Switzerland, the smallest unit of currency is the 5 cent piece. So, for business purposes, we usually often need to round numbers accordingly. Here’s a simple MSSQL function to do just that:

CREATE FUNCTION dbo.ufnRoundCHF (@number money)
RETURNS money
AS
BEGIN
    RETURN Round(2.*@number, 1) / 2
END
GO

This gives the following results:

SELECT dbo.ufnRoundCHF(1.02)  ==> 1.00
SELECT dbo.ufnRoundCHF(1.03)  ==> 1.05
SELECT dbo.ufnRoundCHF(1.06)  ==> 1.05
SELECT dbo.ufnRoundCHF(1.075) ==> 1.10
SELECT dbo.ufnRoundCHF(1.12)  ==> 1.10
SELECT dbo.ufnRoundCHF(1.16)  ==> 1.15
SELECT dbo.ufnRoundCHF(1.19)  ==> 1.20