C# Math Round(Decimal)
Description
Math Round(Decimal)
rounds a decimal value to the nearest
integral value.
Syntax
Math.Round(Decimal)
has the following syntax.
public static decimal Round(
decimal d
)
Parameters
Math.Round(Decimal)
has the following parameters.
d
- A decimal number to be rounded.
Returns
Math.Round(Decimal)
method returns The integer nearest parameter d. If the fractional component of d is halfway
between two integers, one of which is even and the other odd, the even number
is returned. Note that this method returns a Decimal instead of an integral
type.
Example
In the following example, because the floating-point value .1 has no finite binary representation, the first call to the Round(Decimal) method with a value of 11.5 returns 11 instead of 12.
using System;// w w w . j a va 2s . c o m
public class Example
{
public static void Main()
{
decimal value = 11.1M;
Console.WriteLine("{0} --> {1}", value, Math.Round(value));
}
}
The code above generates the following result.