---
title: "NSDecimalAdd(_:_:_:_:)"
framework: foundation
role: symbol
role_heading: Function
path: "foundation/nsdecimaladd(_:_:_:_:)"
---

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

Adds two decimal values.

## Declaration

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

## Discussion

Discussion Adds leftOperand to rightOperand and stores the sum in result. 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 NSDecimalNumber.RoundingMode.up NSDecimalNumber.RoundingMode.plain 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:) in NSDecimalNumberBehaviors. For more information, see Number and Value Programming Topics.

## See Also

### Performing arithmetic using references

- [NSDecimalCompact(_:)](foundation/nsdecimalcompact(_:).md)
- [NSDecimalSubtract(_:_:_:_:)](foundation/nsdecimalsubtract(_:_:_:_:).md)
- [NSDecimalDivide(_:_:_:_:)](foundation/nsdecimaldivide(_:_:_:_:).md)
- [NSDecimalMultiply(_:_:_:_:)](foundation/nsdecimalmultiply(_:_:_:_:).md)
- [NSDecimalMultiplyByPowerOf10(_:_:_:_:)](foundation/nsdecimalmultiplybypowerof10(_:_:_:_:).md)
- [NSDecimalRound(_:_:_:_:)](foundation/nsdecimalround(_:_:_:_:).md)
- [NSDecimalPower(_:_:_:_:)](foundation/nsdecimalpower(_:_:_:_:).md)
- [NSDecimalNormalize(_:_:_:)](foundation/nsdecimalnormalize(_:_:_:).md)
- [Decimal.RoundingMode](foundation/decimal/roundingmode.md)
- [NSDecimalNumber.RoundingMode](foundation/nsdecimalnumber/roundingmode.md)
- [Decimal.CalculationError](foundation/decimal/calculationerror.md)
- [NSDecimalNumber.CalculationError](foundation/nsdecimalnumber/calculationerror.md)
