DecimalMath.Round Method

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.2

Overload List

Round(Decimal) Rounds a decimal value to the nearest integral value.
Round(Decimal, Int32) Rounds a decimal value to a specified number of fractional digits.
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.
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.

Round(Decimal)

Rounds a decimal value to the nearest integral value.
C#
public static decimal Round(
	decimal value
)

Parameters

value  Decimal
A decimal number to be rounded.

Return Value

Decimal
The 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

OverflowException

The result is outside the range of a System.Decimal.

Round(Decimal, Int32)

Rounds a decimal value to a specified number of fractional digits.
C#
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

Decimal
The number nearest to value that contains a number of fractional digits equal to decimals.

Exceptions

ArgumentOutOfRangeException

decimals is less than 0 or greater than 28.

OverflowException

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.
C#
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

Decimal
The 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

ArgumentException

mode is not a valid value of System.MidpointRounding.

OverflowException

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.
C#
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

Decimal
The 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

ArgumentOutOfRangeException

decimals is less than 0 or greater than 28.

ArgumentException

mode is not a valid value of System.MidpointRounding.

OverflowException

The result is outside the range of a System.Decimal.

See Also