@Jonathan Holland said:
if (comparer = CompareType.Greater)
else if (comparer = CompareType.Lesser)
else if (comparer = CompareType.Equals)
if (compareTo == Count)
...one of these is not like the others (though it's the only one that will compile)
@Jonathan Holland said:
if (comparer = CompareType.Greater)
else if (comparer = CompareType.Lesser)
else if (comparer = CompareType.Equals)
if (compareTo == Count)
...one of these is not like the others (though it's the only one that will compile)
Awww, someone doesn't understand floating point -- how cute
Your code is very wrong. It very rarely matches the output of the previous code. That code was a workaround to the default rounding mode of the decimal type in .net (ToEven). It finds the case where the midpoint (.05) is rounded down due to the closest even number being less than the number being rounded.
public static decimal Round(decimal d)
{
return Decimal.Round(d, 1, MidpointRounding.AwayFromZero);
}
would match the output for positive decimals, but would round .05 down if the number is negative. If you add a small increment such as 1e-24 (chosen randomly for nor good reason) like so:
public static decimal Round(decimal d)
{
return Decimal.Round(d + 1e-24m, 1, MidpointRounding.AwayFromZero);
}
It should match for all numbers (depending on the precision maintained )