C# Double CompareTo(Double)

Description

Double CompareTo(Double) compares this instance to a specified double-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified double-precision floating-point number.

Syntax

Double.CompareTo(Double) has the following syntax.


public int CompareTo(
  double value
)

Parameters

Double.CompareTo(Double) has the following parameters.

  • value - A double-precision floating-point number to compare.

Returns

Double.CompareTo(Double) method returns A signed number indicating the relative values of this instance and value. Return Value Description Less than zero This instance is less than value. -or- This instance is not a number (NaN) and value is a number. Zero This instance is equal to value. -or- Both this instance and value are not a number (NaN), PositiveInfinity, or NegativeInfinity. Greater than zero This instance is greater than value. -or- This instance is a number and value is not a number (NaN).

Example

In the following example, however, the computed value turns out to be greater than the original value.


using System;/* ww w  . jav  a  2s .  co m*/

public class Example
{
   public static void Main()
   {
       double value1 = 6.185;
       double value2 = value1 * .1 / .1;
       Console.WriteLine("Comparing {0} and {1}: {2}\n",
                         value1, value2, value1.CompareTo(value2));
       Console.WriteLine("Comparing {0:R} and {1:R}: {2}",
                         value1, value2, value1.CompareTo(value2));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version