在C#.Net中将小数值四舍五入到下一季度(0.25,0.50,0.75)的方法? 我在使用Math.Floor函数进行舍入时出错了
示例:
5.125 -> 5.25
6.390 -> 6.50
7.610 -> 7.75
8.950 -> 9.00
decimal UltimateRounding(decimal amountToRound, decimal nearstOf, decimal
fairness, decimal final)
{
return Math.Floor(amountToRound / nearstOf + fairness + final) * nearstOf;
}
答案 0 :(得分:2)
尝试
var a = 5.125m;
a = Math.Ceiling(a * 4) / 4;