更新时间:2023-01-29 11:14:26
查看官方文档更多。例如:
基本上你给 Math.Round
方法三个参数。
Basically you give the Math.Round
method three parameters.
样code:
var roundedA = Math.Round(1.1, 0); // Output: 1
var roundedB = Math.Round(1.5, 0, MidpointRounding.AwayFromZero); // Output: 2
var roundedC = Math.Round(1.9, 0); // Output: 2
您需要 MidpointRounding.AwayFromZero
是你想被围捕了0.5的值。不幸的是,这不是默认行为 Math.Round()
。
You need MidpointRounding.AwayFromZero
is you want a .5 value to be rounded up. Unfortunately this isn't the default behavior for Math.Round()
.