0 out of 2 rated this helpful - Rate this topic

Math.Round Method

Rounds a value to the nearest integer or specified number of decimal places.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method Static member Round(Decimal) Rounds a decimal value to the nearest integral value.
Public method Static member Round(Double) Rounds a double-precision floating-point value to the nearest integral value.
Public method Static member Round(Decimal, Int32) Rounds a decimal value to a specified number of fractional digits.
Public method Static member Round(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.
Public method Static member Round(Double, Int32) Rounds a double-precision floating-point value to a specified number of fractional digits.
Public method Static member Round(Double, MidpointRounding) Rounds a double-precision floating-point value to the nearest integer. A parameter specifies how to round the value if it is midway between two other numbers.
Public method Static member Round(Decimal, Int32, MidpointRounding) Rounds a decimal value to a specified number of fractional digits. A parameter specifies how to round the value if it is midway between two other numbers.
Public method Static member Round(Double, Int32, MidpointRounding) Rounds a double-precision floating-point value to the specified number of fractional digits. A parameter specifies how to round the value if it is midway between two other numbers.
Top
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
You would think the most common rounding method would be default

The documentation states that symetric arthimetic rounding is the most common rounding method used in the world, but yet the default is bankers rounding. Who the heck decided that bankers rounding should be the default!??!

When I want 74.5 to round to 75, I have to use MidpointRounding.AwayFromZero. Why isn't AwayFromZero the default? Why did you choose a much less common rounding method (Bankers rounding) as the default!?

Why Bankers Rounding?

A major consequence of rounding, of course, is that the rounded data is lost. When those rounded values are used susequently in other numeric or statistical operations, the rounding operation itself can affect the outcome of the operation. If the rounding method being used introduces a bias, the result of a operation can be statistically significant solely because of the method of rounding that was employed.

Depending on the data set, symmetric arithmetic rounding can introduce a major bias, since it always rounds midpoint values upward. To take a simple example, suppose that we want to determine the mean of three values, 1.5, 2.5, and 3.5, but that we want to first round them to the nearest integer before calculating their mean. Note that the true mean of these values is is 2.5. Using symmetic arithmetic rounding, these values change to 2, 3, and 4, and their mean is 3. Using bankers rounding, these values change to 2, 2, and 4, and their mean is 2.67. Because the latter rounding method is much closer to the true mean of the three values, it provides the least loss of data.

In a nutshell, we've chosen banker's rounding rather than the more commonly used symmetic arithmetic rounding because it more closely preserves the unrounded value when that value may be used in subsequent arithmetic operations.

I hope that this helps to answer your question.

--Ron Petrusha
Common Language Runtime Developer Content
Microsoft Corporation