They say you learn something new every day. In IT I learn at least a dozen new things every day. Did you know that there are two different rounding methods in .Net? I didn't. Now I've come across them in two different applications in the same week. They are To Even (Bankers) and Away from Zero.
To Even: When a number is halfway between two others, it is rounded toward the nearest even number.
Away From Zero: When a number is halfway between two others, it is rounded toward the nearest number that is away from zero.
The default MidpointRounding method is MidpointRounding.ToEven. The following are equivalent and both return 0D:
Double roundedValue = Math.Round(0.5D)
Double roundedValue = Math.Round(0.5D, MidpointRounding.ToEven)
When MidpointRounding.AwayFromZero is specified then the result is 1D:
Double roundedValue = Math.Round(0.5D, MidpointRounding.AwayFromZero)