<分区>
Possible Duplicates:
In C#: Math.Round(2.5) result is 2 (instead of 3)! Are you kidding me?
.Net Round Bug
我有一个中间值 (number.5),我需要指定如何对其进行舍入(上限值或下限值。)
我了解带有 MidPointRounding
参数的 Math.Round
的行为,但这并不能解决我的问题:
// To Even
Console.WriteLine(Math.Round(4.4)); // 4
Console.WriteLine(Math.Round(4.5)); // 4
Console.WriteLine(Math.Round(4.6)); // 5
Console.WriteLine(Math.Round(5.5)); // 6
// AwayFromZero
Console.WriteLine(Math.Round(4.4)); // 4
Console.WriteLine(Math.Round(4.5)); // 5
Console.WriteLine(Math.Round(4.6)); // 5
Console.WriteLine(Math.Round(5.5)); // 6
// in one case I need
Console.WriteLine(Math.Round(4.4)); // 4
Console.WriteLine(Math.Round(4.5)); // 4
Console.WriteLine(Math.Round(4.6)); // 5
Console.WriteLine(Math.Round(5.5)); // 5
// another case I need
Console.WriteLine(Math.Round(4.4)); // 4
Console.WriteLine(Math.Round(4.5)); // 5
Console.WriteLine(Math.Round(4.6)); // 5
Console.WriteLine(Math.Round(5.5)); // 6