A provided function of C# in the Math class is the function Round. The round function has two inputs. The first input field is of type double and the number requiring rounding. The second input type is of type int and indicates the precision of the first input field. This round function allows you to provide a degree of precision to your numbers.

public static double Round(double value, int digits)

A few important facts:

  1. When double value is rounded, if it is less than 5, it is rounded down. If it is equal to or greater than 5, the value is rounded up.
  2. Valid int digits are integer between 0 to 14.
  3. An int digit value of 0 will output a whole number.

Provided below is an working example:

double example = 12.34567;
double output = Math.Round(example, 3);

The value output in the above example equal 12.346.

This entry was posted on Friday, March 28th, 2008 at 7:04 am and is filed under C#. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses

  1. Modcorp says

    tank you, it really helped me out.

  2. Daniellle says

    Thanks Vic!

Leave a Reply