ALL,
I am trying to convert Borland C++ code to C#.
In the old code I see the following:
double a = RoundTo( b, -2 );
Looking at Borland documentation I see that RoundTo() accept both positive and negative parameters for precision. Positive means round to 10^n, negative – to 10^-n.
Looking at the C# documentation of Math.RoundTo() I can’t find a reference whether it will accept negative numbers for precision. And all samples are presented with the positive numbers.
What is the proper way of converting the code in this case? Should I just forget about the sign and write:
double a = Math.Round( b, 2 );
Thank you.
Math.Round for doubles in C# cannot accept negative values for digits (in fact it’s documented in that very page to throw an ArgumentOutOfRangeException if digits is less than 0 or greater than 15)
The parameter is in the case of Math.Round instead asking for a certain number of fractional digits which means the sign of the parameter would be reversed, so in your case, yes,
would be a correct translation of RoundTo with a -2 parameter.