I am using Visual C# 2010 Express and am stumped with the Math.Round method.
Two overloads are important to the context of my question:
1- Math.Round(decimal d, int n)
2- Math.Round(double d, int n)
I am trying to round to 5
total base-10 digits. See code snippet below:
int fractional_digits = 4;
double number_to_round = 123.456789;
double rounded_result = Math.Round(number_to_round, fractional_digits);
number_to_round = 11223344.556677;
rounded_result = Math.Round(number_to_round, fractional_digits);
number_to_round = 876.54321E+57;
rounded_result = Math.Round(number_to_round, fractional_digits);
The code is redundant to show the issue three times. The first rounded result gives 123.4568 not 123.46 (or 1.2346E+2) (1 integer + 4
fractional digits).
The second rounded result is 11223344.5567 instead of 11223000 (or 1.1223E+7).
Lastly, the rounded result is 8.7654321E+59 instead of 8.7654E+59.
I need only 5 significant digits. The code example seems to be using method
1 as shown above -
not method
2.
I need method 2. (See comment header copied below).
public static double Round(double value, int digits);
How do I force the compiler to use method 2? Any other suggestions?
I have done a basic search for help on this site (via Google) but all examples only show a single place-value in the integer position.
Thanks in advance.
-EJ