Mono Class Library: System.Math Overview | Members

System.Math.Round Method

Returns the integer nearest the specified decimal. [Edit]

public static decimal Round (decimal d)

Parameters

d
A decimal to be rounded. [Edit]

Returns

A decimal containing the value of the integer nearest d. If d is exactly halfway between two integers, one of which is even and the other odd, then the even integer is returned. [Edit]

Remarks

The behavior of this method follows IEEE Standard 754, section 4.1. [Edit]

Example

The following example demonstrates using the Math.Round(double)(decimal) method.

C# Example
using System;

public class MathRoundExample
{

   public static void Main()
   {

      Double d1 = Math.Round(4.4);
      Double d2 = Math.Round(4.5);
      Double d3 = Math.Round(4.6);
      Console.WriteLine("Math.Round(4.4) returns {0}", d1);
      Console.WriteLine("Math.Round(4.5) returns {0}", d2);
      Console.WriteLine("Math.Round(4.6) returns {0}", d3);

   }

}

The output is

Math.Round(4.4) returns 4
Math.Round(4.5) returns 4
Math.Round(4.6) returns 5

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0