Returns the number nearest the specified double within the specified precision.
A double containing the value of the number nearest value with a precision equal to digits . If the digit in value that is in the 10-(digits + 1) place is equal to 5 and there are no non-zero numbers in any less significant place, then the digit in the 10-digits place will be unchanged if it is even, else it will be set to the closest even integer value in the direction of the digit in the 10-(digits + 1) place. If the precision of value is less than digits, then value is returned unchanged. If digits is zero, this method behaves in the same manner as Math.Round(double) (value ).
Type Reason ArgumentOutOfRangeException digits < 0
-or-
digits > 15
The behavior of this method follows IEEE Standard 754, section 4.1.
The following example demonstrates using the Math.Round(double)(double, int) method.
C# Example
using System; public class MathRoundExample { public static void Main() { Double d1 = Math.Round(3.44,1); Double d2 = Math.Round(3.45,1); Double d3 = Math.Round(3.55,1); Console.WriteLine("Math.Round(3.44, 1) returns {0}", d1); Console.WriteLine("Math.Round(3.45, 1) returns {0}", d2); Console.WriteLine("Math.Round(3.55, 1) returns {0}", d3); } }The output is
Math.Round(3.44, 1) returns 3.4
Math.Round(3.45, 1) returns 3.4
Math.Round(3.55, 1) returns 3.6
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0