Math.Round Method (Decimal)
.NET Framework 1.1
Returns the whole number nearest the specified value.
[Visual Basic] Overloads Public Shared Function Round( _ ByVal d As Decimal _ ) As Decimal [C#] public static decimal Round( decimal d ); [C++] public: static Decimal Round( Decimal d ); [JScript] public static function Round( d : Decimal ) : Decimal;
Parameters
- d
- A Decimal number to be rounded.
Return Value
The whole number nearest parameter d. If d is halfway between two whole numbers, one of which by definition is even and the other odd, then the even number is returned.
Remarks
The behavior of this method follows IEEE Standard 754, section 4. This kind of rounding is sometimes called rounding to nearest, or banker's rounding.
Example
The following code example demonstrates rounding to nearest.
[Visual Basic] Math.Round(4.4) 'Returns 4.0. Math.Round(4.5) 'Returns 4.0. Math.Round(4.6) 'Returns 5.0. [C#] Math.Round(4.4); //Returns 4.0. Math.Round(4.5); //Returns 4.0. Math.Round(4.6); //Returns 5.0. [C++] Math::Round(4.4); //Returns 4.0. Math::Round(4.5); //Returns 4.0. Math::Round(4.6); //Returns 5.0. [JScript] System.Math.Round(4.4) //Returns 4.0. System.Math.Round(4.5) //Returns 4.0. System.Math.Round(4.6) //Returns 5.0.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
Math Class | Math Members | System Namespace | Math.Round Overload List | Ceiling | Floor