How to round decimal value up to nearest 0.05 value?

后端 未结 6 2179
醉梦人生
醉梦人生 2020-12-03 07:33

Is there any way to round up decimal value to its nearest 0.05 value in .Net?

Ex:

7.125 -> 7.15

6.66 -> 6.7

If its now available can anyone

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 08:01

    Something like this should work for any step, not just 0.05:

    private decimal RoundUp (decimal value, decimal step)
    {
        var multiplicand = Math.Ceiling (value / step);
        return step * multiplicand;
    }
    

提交回复
热议问题