C# Math.Round Banker's or Mathematical Method
I wasn't even aware that there was a banker's method to rounding numbers until I came across what I though was a bug in the Math.Round() function in the .NET library today.
If you call this function:
double x = Math.Round(.005, 2);
then you will discover that x is set to zero. If you call this:
double x = Math.Round(.0051, 2);
then x will be set to 0.01.
I was always taught that you round up from 5. This is still correct and is known as the mathematical method of rounding. However I have recently learned that there's another method and if the least-significant-digit is 5 and you're using the banker's method then you round down instead of up. This is the method that Math.Round() uses by default.
If you want to use the expected mathematical method for the round function then you need to add another parameter to the overloaded Round() function which specifies how you want it to handle midpoint rounding. AwayFromZero will do the trick:
double x = Math.Round(.005, 2, MidpointRounding.AwayFromZero);
This will cause x to be set to .001 as you would expect. The other value defined in the MidpointRounding enum is ToEven and this will do the default of round the midpoint down to zero.
Mystery solved!