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();
結果是 :c#
0.5ide
0.4spa
0.4ci
Math.Round(a,1,MidpointRounding.AwayFromZero) 爲經常使用的 四捨五入string
MidpointRounding.AwayFromZeroit
當一個數字是其餘兩個數字的中間值時,會將其舍入爲兩個值中絕對值較小的值 應該是 絕對值較大的值class