C# .Net Round Up method with precision selection

This method will round a double up.


public static double RoundUp(double figure, int precision)
{
double newFigure = Math.Round(figure, precision);
double difference = figure - newFigure;
double tolerance = 1 / Math.Pow(10, precision + 1);
if (difference > tolerance) //Figure was rounded down
{
double padding = 1 / Math.Pow(10, precision);
newFigure += padding;
}
return newFigure;
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: