Decimal::Round Method (Decimal, MidpointRounding)
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)
A decimal number to round.
A value that specifies how to round d if it is midway between two other numbers.
Return ValueType: System::Decimal
The integer that is nearest to the d parameter. If d is halfway between two numbers, one of which is even and the other odd, the mode parameter determines which of the two numbers is returned.
In a midpoint value, the value after the least significant digit in the result is precisely half way between two numbers. For example, 7.5 is a midpoint value if it is to be rounded to an integer. For midpoint values, the nearest value can't be easily identified without a rounding convention, which is specified by the mode argument. Themethod supports two rounding conventions for handling midpoint values.
- Rounding away from zero.
Midpoint values are rounded to the next number away from zero. For example, 3.5 rounds to 4, 4.5 rounds to 5, -3.5 rounds to -4, and -4.5 rounds to -5. This form of rounding is represented by the MidpointRounding::AwayFromZero enumeration member.
Rounding away from zero is the most widely known form of rounding.
- Rounding to even, or banker's rounding
Midpoint values are rounded to the nearest even number. For example, both 3.5 and 4.5 round to 4, and both -3.5 and -4.5 round to -4. This form of rounding is represented by the MidpointRounding::ToEven enumeration member.
Rounding to nearest is the standard form of rounding used in financial and statistical operations. It conforms to IEEE Standard 754, section 4. When used in multiple rounding operations, it reduces the rounding error that is caused by consistently rounding midpoint values in a single direction. In some cases, this rounding error can be significant.
Available since 2.0