C# Decimal Round(Decimal, MidpointRounding)
Description
Decimal Round(Decimal, MidpointRounding)
rounds a
decimal value to the nearest integer. A parameter specifies how to round
the value if it is midway between two other numbers.
Syntax
Decimal.Round(Decimal, MidpointRounding)
has the following syntax.
public static decimal Round(
decimal d,
MidpointRounding mode
)
Parameters
Decimal.Round(Decimal, MidpointRounding)
has the following parameters.
d
- A decimal number to round.mode
- A value that specifies how to round d if it is midway between two other numbers.
Returns
Decimal.Round(Decimal, MidpointRounding)
method returns The integer that is nearest to the d parameter. If d is halfway between two
numbers, one of which is even and the other odd, the mode parameter determines
which of the two numbers is returned.
Example
Example of the decimal.Round(Decimal, MidpointRounding)
method.
using System;/* w w w. j a v a 2s . c om*/
class DecimalRoundDemo
{
public static void Main( )
{
decimal rounded = decimal.Round( 1.45M, MidpointRounding.AwayFromZero );
Console.WriteLine( rounded );
}
}
The code above generates the following result.