I am using Math.Round(decimal d, int decimals)
in C# to round decimals to a specified number of decimal places. I can round to 15 decimal places, but when I try and round to 16, for example, I get the following exception:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll Additional information: Rounding digits must be between 0 and 15, inclusive.
Is there any way of rounding to a higher number of decimal places, perhaps without the use of Math.Round
?
To give slightly more background to the problem, I am calculating irrational mathematical constants such as 'pi' and 'e', and letting the user specify the number of decimal places to calculate to. The boolean to check whether or not the value and the previous value are identical to the given accuracy is as follows:
Math.Round(valuePrevious, decPlaces) == Math.Round(valueCurrent, decPlaces)