November 12, 2009

Math.Round

Math.Round() can be made to work in the conventional manner for rounding numbers using the 'MidpointRounding.AwayFromZero' argument eg
// Round to 2 decimal places. 
public double RoundUpTo2Dp(double arg)
{
  // so xx.xx5 becomes xx.x(x+1)0 where x is a digit in a double number
  return Math.Round(arg, 2, MidpointRounding.AwayFromZero); 
}

No comments: