<!--
{
  "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/NSDecimalNumber",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDecimalNumber"
  },
  "title" : "NSDecimalNumber"
}
-->

# NSDecimalNumber

An object for representing and performing arithmetic on base-10 numbers.

```
class NSDecimalNumber
```

## Overview

In Swift, this object bridges to [`Decimal`](/documentation/Foundation/Decimal); use [`NSDecimalNumber`](/documentation/Foundation/NSDecimalNumber) when you need reference semantics or other Foundation-specific behavior.

`NSDecimalNumber`, an immutable subclass of `NSNumber`, provides an object-oriented wrapper for doing base-10 arithmetic. An instance can represent any number that can be expressed as `mantissa x 10^exponent` where mantissa is a decimal integer up to 38 digits long, and exponent is an integer from –128 through 127.

> Important:
> The Swift overlay to the Foundation framework provides the ``doc://com.apple.foundation/documentation/Foundation/Decimal`` structure, which bridges to the ``doc://com.apple.foundation/documentation/Foundation/NSDecimalNumber`` class. For more information about value types, see <doc://com.apple.documentation/documentation/Swift/working-with-foundation-types>.

## Topics

### Creating a Decimal Number

[`decimalNumberWithDecimal:`](/documentation/Foundation/NSDecimalNumber/decimalNumberWithDecimal:)

Creates and returns a decimal number equivalent to a given decimal structure.

[`decimalNumberWithMantissa:exponent:isNegative:`](/documentation/Foundation/NSDecimalNumber/decimalNumberWithMantissa:exponent:isNegative:)

Creates and returns a decimal number equivalent to the number specified by the arguments.

[`decimalNumberWithString:`](/documentation/Foundation/NSDecimalNumber/decimalNumberWithString:)

Creates a decimal number whose value is equivalent to that in a given numeric string.

[`decimalNumberWithString:locale:`](/documentation/Foundation/NSDecimalNumber/decimalNumberWithString:locale:)

Creates a decimal number whose value is equivalent to that in a given numeric string, interpreted using a given locale.

[`one`](/documentation/Foundation/NSDecimalNumber/one)

A decimal number equivalent to the number 1.0.

[`zero`](/documentation/Foundation/NSDecimalNumber/zero)

A decimal number equivalent to the number 0.0.

[`notANumber`](/documentation/Foundation/NSDecimalNumber/notANumber)

A decimal number that specifies no number.

### Initializing a Decimal Number

[`init(decimal:)`](/documentation/Foundation/NSDecimalNumber/init(decimal:))

Initializes a decimal number to represent a given decimal.

[`init(mantissa:exponent:isNegative:)`](/documentation/Foundation/NSDecimalNumber/init(mantissa:exponent:isNegative:))

Initializes a decimal number using the given mantissa, exponent, and sign.

[`init(string:)`](/documentation/Foundation/NSDecimalNumber/init(string:))

Initializes a decimal number so that its value is equivalent to that in a given numeric string.

[`init(string:locale:)`](/documentation/Foundation/NSDecimalNumber/init(string:locale:))

Initializes a decimal number so that its value is equivalent to that in a given numeric string, interpreted using a given locale.

### Performing Arithmetic

[`adding(_:)`](/documentation/Foundation/NSDecimalNumber/adding(_:))

Adds this number to another given number.

[`subtracting(_:)`](/documentation/Foundation/NSDecimalNumber/subtracting(_:))

Subtracts another given number from this one.

[`multiplying(by:)`](/documentation/Foundation/NSDecimalNumber/multiplying(by:))

Multiplies the number by another given number.

[`dividing(by:)`](/documentation/Foundation/NSDecimalNumber/dividing(by:))

Divides the number by another given number.

[`raising(toPower:)`](/documentation/Foundation/NSDecimalNumber/raising(toPower:))

Raises the number to a given power.

[`multiplying(byPowerOf10:)`](/documentation/Foundation/NSDecimalNumber/multiplying(byPowerOf10:))

Multiplies the number by 10 raised to the given power.

[`adding(_:withBehavior:)`](/documentation/Foundation/NSDecimalNumber/adding(_:withBehavior:))

Adds this number to another given number using the specified behavior.

[`subtracting(_:withBehavior:)`](/documentation/Foundation/NSDecimalNumber/subtracting(_:withBehavior:))

Subtracts this a given number from this one using the specified behavior.

[`multiplying(by:withBehavior:)`](/documentation/Foundation/NSDecimalNumber/multiplying(by:withBehavior:))

Multiplies this number by another given number using the specified behavior.

[`dividing(by:withBehavior:)`](/documentation/Foundation/NSDecimalNumber/dividing(by:withBehavior:))

Divides this number by another given number using the specified behavior.

[`raising(toPower:withBehavior:)`](/documentation/Foundation/NSDecimalNumber/raising(toPower:withBehavior:))

Raises the number to a given power using the specified behavior.

[`multiplying(byPowerOf10:withBehavior:)`](/documentation/Foundation/NSDecimalNumber/multiplying(byPowerOf10:withBehavior:))

Multiplies the number by 10 raised to the given power using the specified behavior.

### Rounding Off

[`rounding(accordingToBehavior:)`](/documentation/Foundation/NSDecimalNumber/rounding(accordingToBehavior:))

Returns a rounded version of the decimal number using the specified rounding behavior.

### Managing Behavior

[`defaultBehavior`](/documentation/Foundation/NSDecimalNumber/defaultBehavior)

The way arithmetic methods round off and handle error conditions.

[`NSDecimalNumberBehaviors`](/documentation/Foundation/NSDecimalNumberBehaviors)

A protocol that declares three methods that control the discretionary aspects of working with decimal numbers.

[`NSDecimalNumberHandler`](/documentation/Foundation/NSDecimalNumberHandler)

A class that adopts the decimal number behaviors protocol.

### Accessing the Value

[`decimalValue`](/documentation/Foundation/NSDecimalNumber/decimalValue)

The decimal number’s value, expressed as an [`Decimal`](/documentation/Foundation/Decimal) structure.

[`doubleValue`](/documentation/Foundation/NSDecimalNumber/doubleValue)

The decimal number’s closest approximate `double` value.

[`description(withLocale:)`](/documentation/Foundation/NSDecimalNumber/description(withLocale:))

Returns a string representation of the decimal number appropriate for the specified locale.

[`objCType`](/documentation/Foundation/NSDecimalNumber/objCType)

A C string containing the Objective-C type for the data contained in the decimal number object.

### Comparing Decimal Numbers

[`compare(_:)`](/documentation/Foundation/NSDecimalNumber/compare(_:))

Compares this decimal number and another.

### Getting Maximum and Minimum Possible Values

[`maximum`](/documentation/Foundation/NSDecimalNumber/maximum)

Returns the largest possible value of a decimal number.

[`minimum`](/documentation/Foundation/NSDecimalNumber/minimum)

Returns the smallest possible value of a decimal number.

### Recognizing Exceptions

Exceptions with these names may be raised to indicate computational errors with decimal numbers.

[`decimalNumberExactnessException`](/documentation/Foundation/NSExceptionName/decimalNumberExactnessException)

The exception raised if there is an exactness error.

[`decimalNumberOverflowException`](/documentation/Foundation/NSExceptionName/decimalNumberOverflowException)

The exception raised on overflow.

[`decimalNumberUnderflowException`](/documentation/Foundation/NSExceptionName/decimalNumberUnderflowException)

The exception raised on underflow.

[`decimalNumberDivideByZeroException`](/documentation/Foundation/NSExceptionName/decimalNumberDivideByZeroException)

The exception raised on divide by zero.



---

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)