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: SystemAssembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax 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:
DecimalThe 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 Exception | Condition |
---|
ArgumentOutOfRangeException | decimals is less than 0 or greater than 28. |
ArgumentException | mode is not a valid value of MidpointRounding. |
OverflowException | The result is outside the range of a Decimal. |
See Also