---
title: "compare(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdecimalnumber/compare(_:)"
---

# compare(_:)

Compares this decimal number and another.

## Declaration

```swift
func compare(_ decimalNumber: NSNumber) -> ComparisonResult
```

## Parameters

- `decimalNumber`: The number with which to compare the receiver. This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of macOS.

## Return Value

Return Value NSOrderedAscending if the value of decimalNumber is greater than the receiver; NSOrderedSame if they’re equal; and NSOrderedDescending if the value of decimalNumber is less than the receiver.
