你怎么圆了许多在C#小数点后两位?
问题描述:
我想这样做,使用 Math.Round
函数
答
下面是一个例子:
decimal a = 1.994444M;
Math.Round(a, 2); //returns 1.99
decimal b = 1.995555M;
Math.Round(b, 2); //returns 2.00
您可能也想看看银行家四舍五入/舍入到甚至以下过载:
You might also want to look at bankers rounding / round-to-even with the following overload:
Math.Round(a, 2, MidpointRounding.ToEven);
还有更多的信息在这里 。
There's more information on it here.