Decimal.Compare Method (Decimal, Decimal)


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

Compares two specified Decimal values.

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

static member Compare : 
        d1:decimal *
        d2:decimal -> int


Type: System.Decimal

The first value to compare.

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


Less than zero

d1 is less than d2.


d1 and d2 are equal.

Greater than zero

d1 is greater than d2.

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.

No code example is currently available or this language may not be supported.

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