Mono Class Library: System.Math Overview | MembersSystem.Math.Round Method |
Returns the number nearest the specified double within the specified precision. [Edit]
|
- value
- A double to be rounded. [Edit]
- digits
- A int containing the value of the number of significant fractional digits (precision) in the return value. This number is required to be greater than or equal to 0 and less than or equal to 15. [Edit]
- digits
- Documentation for this section has not yet been entered. [Edit]
A double containing the value of the number nearest value with a precision equal to digits . If the digit in value that is in the 10-(digits + 1) place is equal to 5 and there are no non-zero numbers in any less significant place, then the digit in the 10-digits place will be unchanged if it is even, else it will be set to the closest even integer value in the direction of the digit in the 10-(digits + 1) place. If the precision of value is less than digits, then value is returned unchanged. If digits is zero, this method behaves in the same manner as Math.Round(double) (value ). [Edit]
Type Reason ArgumentOutOfRangeException digits < 0
-or-
digits > 15
[Edit]
The behavior of this method follows IEEE Standard 754, section 4.1. [Edit]
The following example demonstrates using the Math.Round(double)(double, int) method.
C# Example using System; public class MathRoundExample { public static void Main() { Double d1 = Math.Round(3.44,1); Double d2 = Math.Round(3.45,1); Double d3 = Math.Round(3.55,1); Console.WriteLine("Math.Round(3.44, 1) returns {0}", d1); Console.WriteLine("Math.Round(3.45, 1) returns {0}", d2); Console.WriteLine("Math.Round(3.55, 1) returns {0}", d3); } }The output is
Math.Round(3.44, 1) returns 3.4
Math.Round(3.45, 1) returns 3.4
Math.Round(3.55, 1) returns 3.6
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0