dlyangph
unread,Oct 28, 2009, 4:31:40 AM10/28/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 鸿蒙之巅
MidpointRounding.AwayFromZero
Math.Round (Decimal, Int32, MidpointRounding)
using System;
class Program
{
static void Main(string[] args)
{
// 以下では小数点第2位で「四捨五入」を行う
Console.WriteLine("四捨五入");
const MidpointRounding away = MidpointRounding.AwayFromZero;
decimal AwayFromZero105 = Math.Round(1.05m, 1, away);
Console.WriteLine(AwayFromZero105); // 出力:1.1
decimal AwayFromZero115 = Math.Round(1.15m, 1, away);
Console.WriteLine(AwayFromZero115); // 出力:1.2
decimal AwayFromZero125 = Math.Round(1.25m, 1, away);
Console.WriteLine(AwayFromZero125); // 出力:1.3
decimal AwayFromZero135 = Math.Round(1.35m, 1, away);
Console.WriteLine(AwayFromZero135); // 出力:1.4
// 以下では小数点第2位で「最近接偶数への丸め」を行う
Console.WriteLine("最近接偶数への丸め");
const MidpointRounding even = MidpointRounding.ToEven;
decimal NearestEven105 = Math.Round(1.05m, 1, even);
Console.WriteLine(NearestEven105); // 出力:1.0
decimal NearestEven115 = Math.Round(1.15m, 1, even);
Console.WriteLine(NearestEven115); // 出力:1.2
decimal NearestEven125 = Math.Round(1.25m, 1, even);
Console.WriteLine(NearestEven125); // 出力:1.2
decimal NearestEven135 = Math.Round(1.35m, 1, even);
Console.WriteLine(NearestEven135); // 出力:1.4
}
}