Hi,
According to msdn defenition for rounding methods :
-----------------------------------------------------------------------------------------------
ToEven - When a number is halfway between two others, it is rounded toward the nearest even number.
AwayFromZero - When a number is halfway between two others, it is rounded toward the nearest number that is away from zero.
-----------------------------------------------------------------------------------------------
however when trying to use Math.Round i get these results :
double x1 = Math.Round(2.1125, 3, MidpointRounding.ToEven); // Result 2.112
double x2 = Math.Round(2.1125, 3, MidpointRounding.AwayFromZero); // Result 2.113
double x3 = Math.Round(2.1135, 3, MidpointRounding.ToEven); // Result 2.114
double x4 = Math.Round(2.1135, 3, MidpointRounding.AwayFromZero); // Result 2.114
double y1 = Math.Round(2.125, 2, MidpointRounding.ToEven); // Result 2.12
double y2 = Math.Round(2.125, 2, MidpointRounding.AwayFromZero); // Result 2.13
double y3 = Math.Round(2.135, 2, MidpointRounding.ToEven); // Result 2.13
double y4 = Math.Round(2.135, 2, MidpointRounding.AwayFromZero); // Result 2.13
when rounding 3 decimals the result is expected.
but when rounding 2 decimals I get a wrong result.
y3 should return 2.14 because we are rounding to EVEN numbers.
y4 should return 2.14 becuase we are rounding away from zero.
I dont understand the results. Can anyone please explain them to me ?
Eldad.