System.Math.Round Method

Rounds a double-precision floating-point value to a specified number of fractional digits.

Syntax

public static double Round (double value, int digits)

Parameters

digits
The number of fractional digits in the return value.
value
A double-precision floating-point number to be rounded.
digits
The number of fractional digits in the return value.

Returns

The number nearest to value that contains a number of fractional digits equal to digits.

Exceptions

TypeReason
ArgumentOutOfRangeException

digits < 0

-or-

digits > 15

Remarks

Note:

For examples and comprehensive usage information about this and other overloads of the Round method, see the erload:System.Math.Round reference page.

Example

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

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0