Math.Round Method (Decimal, MidpointRounding)
July 28, 2014
Rounds a decimal value to the nearest integer. A parameter specifies how to round the value if it is midway between two other numbers.
Assembly: mscorlib (in mscorlib.dll)
- Type: System.Decimal
A decimal number to be rounded.
- Type: System.MidpointRounding
Specification for how to round d if it is midway between two other numbers.
Return ValueType: System.Decimal
The integer nearest d. If d is halfway between two numbers, one of which is even and the other odd, then mode determines which of the two is returned.
The mode parameter controls how d is rounded if the fractional component of d is halfway between the one's digit and a value one greater than the one's digit. mode can have one of the following two values:
MidpointRounding.ToEven. If the one's digit 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.
MidpointRounding.AwayFromZero. The one's digit is always rounded up to the next digit. This is the most commonly known rounding method. It is known as symmetric arithmetic rounding.