Math.Round Method (Decimal, Int32)
July 28, 2014
Rounds a decimal value to a specified number of fractional digits.
Assembly: mscorlib (in mscorlib.dll)
- Type: System.Decimal
A decimal number to be rounded.
- Type: System.Int32
The number of decimal places in the return value.
Return ValueType: System.Decimal
The number nearest d with a number of fractional digits equal to decimals.
The decimals parameter specifies the number of fractional digits in the return value and ranges from 0 to 28. If decimals is zero, an integer is returned.
If the value of the digits in d to the right of the decimals position is halfway between the digit in position decimals, that digit is rounded up if it is odd, or left unchanged if it is even. If the precision of d is less than decimals, d is returned unchanged.
The behavior of this method follows IEEE Standard 754, section 4. This kind of rounding 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.