asp.net.ph

Math.Round Method ( Double, Int32 )

System Namespace   Math Class


Returns the number with the specified precision nearest the specified value.

[ VB ]
Overloads Public Shared Function Round ( _
   ByVal value As Double, _
   ByVal digits As Integer _
) As Double

[ C# ]
public static double Round (
   double value,
   int digits
);

[ C++ ]
public: static double Round (
   double value,
   int digits
);

[ JScript ]
public static function Round (
   value : double,
   digits : int
) : double;

Parameters

value
A double-precision floating-point number to be rounded.
digits
The number of significant fractional digits ( precision ) in the return value.

Return Value

The number nearest value with precision equal to digits. If value is halfway between two numbers, one of which is even and the other odd, then the even number is returned. If the precision of value is less than digits, then value is returned unchanged.

Remarks

The digits parameter specifies the number of significant fractional digits in the return value and ranges from 0 to 15. If digits is zero, then a whole number is returned.

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. If digits is zero, this kind of rounding is sometimes called rounding toward zero.

Example

[ Visual Basic, C#, C++ ] The following code example demonstrates rounding to nearest.

[ VB ] 
Math.Round ( 3.44, 1 ) 'Returns 3.4.
Math.Round ( 3.45, 1 ) 'Returns 3.4.
Math.Round ( 3.46, 1 ) 'Returns 3.5.

[ C# ] 
Math.Round ( 3.44, 1 ); //Returns 3.4.
Math.Round ( 3.45, 1 ); //Returns 3.4.
Math.Round ( 3.46, 1 ); //Returns 3.5.

[ C++ ] 

Math::Round ( 3.44, 1 ); //Returns 3.4.
Math::Round ( 3.45, 1 ); //Returns 3.4.
Math::Round ( 3.46, 1 ); //Returns 3.5.
See Also

Math Members   Math.Round Overload List   Ceiling   Floor Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph