Tuesday, September 16, 2008

Microsoft .NET MidpointRounding Enumeration

The MidPointRounding enumeration is used in certain overloads to the Round method on the Math class in the .NET Framework.

Introduced with the 2.0 framework, the enumeration is designed to provide additional control over the rounding process.

The current possible choices for the enumeration are AwayFromZero and ToEven.

From MSDN:
ToEven: When a number is halfway between two others, it is rounded toward the nearest even number.
AwayFromZero: When a number is halfway between two others, it is rounded toward the nearest number that is away from zero.

This is a demonstration of the typical signature for a Round method with the MidpointRounding overload:
public static double Round(double value, int digits, MidpointRounding mode);
public static double Round(double value, MidpointRounding mode);

Here is the article on MSDN: http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx

Microsoft 2.0 Framework article on MidpointRounding Enumeration
Microsoft 3.0 Framework article on MidpointRounding Enumeration
Microsoft 3.5 Framework article on MidpointRounding Enumeration

No comments: