Windows apps
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

# Decimal.Compare Method (Decimal, Decimal)

.NET Framework (current version)

Note

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Compares two specified Decimal values.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

## Syntax

```public static int Compare(
decimal d1,
decimal d2
)
```

#### Parameters

d1
Type: System.Decimal

The first value to compare.

d2
Type: System.Decimal

The second value to compare.

#### Return Value

Type: System.Int32

A signed number indicating the relative values of d1 and d2.

Return value

Meaning

Less than zero

d1 is less than d2.

Zero

d1 and d2 are equal.

Greater than zero

d1 is greater than d2.

## Examples

The following example compares several Decimal values. Note that the first comparison indicates that the two values are equal despite the subtraction operation performed on the value2 variable. This is because the Decimal type has 29 digits of precision, whereas a difference between these two values can be detected only with 30 digits of precision.

```using System;

public enum Relationship
{  LessThan = -1, Equals = 0, GreaterThan = 1 }

public class Example
{
public static void Main()
{
decimal value1 = Decimal.MaxValue;
decimal value2 = value1 - .01m;
Console.WriteLine("{0} {2} {1}", value1, value2,
(Relationship) Decimal.Compare(value1, value2));

value2 = value1 / 12m - .1m;
value1 = value1 / 12m;
Console.WriteLine("{0} {2} {1}", value1, value2,
(Relationship) Decimal.Compare(value1, value2));

value1 = value1 - .2m;
value2 = value2 + .1m;
Console.WriteLine("{0} {2} {1}", value1, value2,
(Relationship) Decimal.Compare(value1, value2));
}
}
// The example displays the following output:
//     79228162514264337593543950335 Equals 79228162514264337593543950335
//     6602346876188694799461995861.2 GreaterThan 6602346876188694799461995861.1
//     6602346876188694799461995861.0 LessThan 6602346876188694799461995861.2
```

## Version Information

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1