C# Math Round(Double, Int32)
Description
Math Round(Double, Int32)
rounds a double-precision
floating-point value to a specified number of fractional digits.
Syntax
Math.Round(Double, Int32)
has the following syntax.
public static double Round(
double value,
int digits
)
Parameters
Math.Round(Double, Int32)
has the following parameters.
value
- A double-precision floating-point number to be rounded.digits
- The number of fractional digits in the return value.
Returns
Math.Round(Double, Int32)
method returns The number nearest to value that contains a number of fractional digits equal
to digits.
Example
The following code shows how to use Math.Round(Double, Int32)
method.
using System;/* w w w. j av a 2s . c o m*/
public class Example
{
public static void Main()
{
double[] values = { 2.125, 2.135, 2.145, 3.125, 3.135, 3.145 };
foreach (double value in values)
Console.WriteLine("{0} --> {1}", value, Math.Round(value, 2));
}
}
The code above generates the following result.