<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDecimalAdd(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@NSDecimalAdd"
  },
  "title" : "NSDecimalAdd(_:_:_:_:)"
}
-->

# NSDecimalAdd(_:_:_:_:)

Adds two decimal values.

```
func NSDecimalAdd(_ result: UnsafeMutablePointer<Decimal>, _ leftOperand: UnsafePointer<Decimal>, _ rightOperand: UnsafePointer<Decimal>, _ roundingMode: NSDecimalNumber.RoundingMode) -> NSDecimalNumber.CalculationError
```

## Discussion

Adds `leftOperand` to `rightOperand` and stores the sum in `result`. [`Decimal`](/documentation/Foundation/Decimal) instances can represent a number with up to 38 significant digits. If a number is more precise than that, it must be rounded off. `roundingMode` determines how to round it off. There are four possible rounding modes:

- [`NSDecimalNumber.RoundingMode.down`](/documentation/Foundation/NSDecimalNumber/RoundingMode/down)
- [`NSDecimalNumber.RoundingMode.up`](/documentation/Foundation/NSDecimalNumber/RoundingMode/up)
- [`NSDecimalNumber.RoundingMode.plain`](/documentation/Foundation/NSDecimalNumber/RoundingMode/plain)
- [`NSDecimalNumber.RoundingMode.bankers`](/documentation/Foundation/NSDecimalNumber/RoundingMode/bankers)

The return value indicates whether any machine limitations were encountered in the addition. If none were encountered, the function returns `NSCalculationNoError`. Otherwise it may return one of the following values: `NSCalculationLossOfPrecision`, `NSCalculationOverflow` or `NSCalculationUnderflow`. For descriptions of all these error conditions, see [`exceptionDuringOperation(_:error:leftOperand:rightOperand:)`](/documentation/Foundation/NSDecimalNumberBehaviors/exceptionDuringOperation(_:error:leftOperand:rightOperand:)) in NSDecimalNumberBehaviors.

For more information, see [Number and Value Programming Topics](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NumbersandValues/NumbersandValues.html#//apple_ref/doc/uid/10000038i).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)