Decimal Math.Round Method
Definition
Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.2
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.2
Overload List
Round( | Rounds a decimal value to the nearest integral value. |
Round( | Rounds a decimal value to a specified number of fractional digits. |
Round( | Rounds a decimal value to the nearest integer. A parameter specifies how to round the value if it is midway between two other numbers. |
Round( | 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. |
Round(Decimal)
Rounds a decimal value to the nearest integral value.
public static decimal Round(
decimal value
)
Parameters
- value Decimal
- A decimal number to be rounded.
Return Value
DecimalThe integer nearest parameter value. If the fractional component of value 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 System.Decimal instead of an integral type.
Exceptions
Overflow | The result is outside the range of a System.Decimal. |
Round(Decimal, Int32)
Rounds a decimal value to a specified number of fractional digits.
public static decimal Round(
decimal value,
int decimals
)
Parameters
- value Decimal
- A decimal number to be rounded.
- decimals Int32
- The number of decimal places in the return value.
Return Value
DecimalThe number nearest to value that contains a number of fractional digits equal to decimals.
Exceptions
Argument | decimals is less than 0 or greater than 28. |
Overflow | The result is outside the range of a System.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.
public static decimal Round(
decimal value,
MidpointRounding mode
)
Parameters
- value Decimal
- A decimal number to be rounded.
- mode MidpointRounding
- Specification for how to round value if it is midway between two other numbers.
Return Value
DecimalThe integer nearest value. If value is halfway between two numbers, one of which is even and the other odd, then mode determines which of the two is returned.
Exceptions
Argument | mode is not a valid value of System.MidpointRounding. |
Overflow | The result is outside the range of a System.Decimal. |
Round(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.
public static decimal Round(
decimal value,
int decimals,
MidpointRounding mode
)
Parameters
- value Decimal
- A decimal number to be rounded.
- decimals Int32
- The number of decimal places in the return value.
- mode MidpointRounding
- Specification for how to round value if it is midway between two other numbers.
Return Value
DecimalThe number nearest to value that contains a number of fractional digits equal to decimals. If the number of fractional digits in value is less than decimals, value is returned unchanged.
Exceptions
Argument | decimals is less than 0 or greater than 28. |
Argument | mode is not a valid value of System.MidpointRounding. |
Overflow | The result is outside the range of a System.Decimal. |