decimal a = 0.45M; Console.WriteLine(Math.Round(a,1,MidpointRounding.AwayFromZero)); Console.WriteLine(Math.Round(a,1,MidpointRounding.ToEven)); Console.WriteLine(Math.Round(a,1)); string dateStr = DateTime.Now.ToString("MMM dd", CultureInfo.CreateSpecificCulture("en-US")); Console.ReadLine();
结果是 :
0.5
0.4
0.4
Math.Round(a,1,MidpointRounding.AwayFromZero) 为常用的 四舍五入
MidpointRounding.AwayFromZero
当一个数字是其他两个数字的中间值时,会将其舍入为两个值中绝对值较小的值 应该是 绝对值较大的值