四舍五入的国际惯例
static void Main(string[] args)
{
var n1 = 1.5;
var n2 = 2.5;
var n3 = 3.5;
var n4 = 4.5;
var n5 = 5.5;
Console.WriteLine(Math.Round(n1));
Console.WriteLine(Math.Round(n2));
Console.WriteLine(Math.Round(n3));
Console.WriteLine(Math.Round(n4));
Console.WriteLine(Math.Round(n5));
Console.Read();
{
var n1 = 1.5;
var n2 = 2.5;
var n3 = 3.5;
var n4 = 4.5;
var n5 = 5.5;
Console.WriteLine(Math.Round(n1));
Console.WriteLine(Math.Round(n2));
Console.WriteLine(Math.Round(n3));
Console.WriteLine(Math.Round(n4));
Console.WriteLine(Math.Round(n5));
Console.Read();
}
//输出结果: 2 2 4 4 6 (四舍五入也有个国际惯例,叫奇进偶舍,意思是当舍入位前面一位是奇数时,就进,为偶数时,就舍,这也是体现公平性的原理)
解决方法(中国式四舍五入):
Math.Round(price,2,MidpointRounding.AwayFromZero)