Click or drag to resize
MathRound Method (Decimal, Int32, MidpointRounding)
Rounds a decimal value to a specified number of fractional digits. A parameter specifies how to round the value if it is midway between two other numbers.

Namespace: System
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public static decimal Round(
	decimal d,
	int decimals,
	MidpointRounding mode
)

Parameters

d
Type: SystemDecimal
A decimal number to be rounded.
decimals
Type: SystemInt32
The number of decimal places in the return value.
mode
Type: SystemMidpointRounding
Specification for how to round d if it is midway between two other numbers.

Return Value

Type: Decimal
The number nearest to d that contains a number of fractional digits equal to decimals. If d has fewer fractional digits than decimals, d is returned unchanged.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptiondecimals is less than 0 or greater than 28.
ArgumentExceptionmode is not a valid value of MidpointRounding.
OverflowExceptionThe result is outside the range of a Decimal.
See Also