# .NET Math.Round問題

0

MidpointRounding.ToEven. If the digit in the decimals position is odd, it is changed to an even digit. Otherwise, it is left unchanged. This behavior follows IEEE Standard 754, section 4. It is sometimes called rounding to nearest, or banker's rounding. It minimizes rounding errors that result from consistently rounding a midpoint value in a single direction.

AwayFromZero. The digit in the decimals position is always rounded up to the next digit. This is the most commonly known rounding method. It is known as symmetric arithmetic rounding.

banker's rounding

Console.WriteLine(Math.Round(1.225,2,MidpointRounding.ToEven));

Console.WriteLine(Math.Round(1.265,2,MidpointRounding.AwayFromZero));

MingQ | 菜鸟二级 | 园豆：312

0

```//Math.cs
public static double Round(double value, int digits, MidpointRounding mode)```

```//Math.cs
public static decimal Round(decimal d, int decimals, MidpointRounding mode)```

0

Console.WriteLine(Math.Round(1.225M,2,MidpointRounding.ToEven));

Launcher | 园豆：45050 (高人七级) | 2012-12-11 11:37

@MingQ: 1.225M 表示是 decimal 类型，1.225 表示是 double 类型，decimal 精度比 double 高，可以完整的表示 0.005，而 double 不行，实际会被表示为 0.00499999999.....。这样你在 Round 的时候，第三位就不是 5，而是 4 了。

@Launcher: 学习了

您需要登录以后才能回答，未注册用户请先注册