Class

# NSDecimalNumber

`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.

## Symbols

### Creating a Decimal Number

`class var one: NSDecimalNumber`

Returns an `NSDecimalNumber` object equivalent to the number 1.0.

`class var zero: NSDecimalNumber`

Returns an `NSDecimalNumber` object equivalent to the number 0.0.

`class var notANumber: NSDecimalNumber`

Returns an `NSDecimalNumber` object that specifies no number.

### Initializing a Decimal Number

`init(decimal: Decimal)`

Returns an `NSDecimalNumber` object initialized to represent a given decimal.

`init(mantissa: UInt64, exponent: Int16, isNegative: Bool)`

Returns an `NSDecimalNumber` object initialized using the given mantissa, exponent, and sign.

`init(string: String?)`

Returns an `NSDecimalNumber` object initialized so that its value is equivalent to that in a given numeric string.

`init(string: String?, locale: Any?)`

Returns an `NSDecimalNumber` object initialized so that its value is equivalent to that in a given numeric string, interpreted using a given locale.

### Performing Arithmetic

`func adding(NSDecimalNumber)`

Returns a new `NSDecimalNumber` object whose value is the sum of the receiver and another given `NSDecimalNumber` object.

`func subtracting(NSDecimalNumber)`

Returns a new `NSDecimalNumber` object whose value is that of another given `NSDecimalNumber` object subtracted from the value of the receiver.

`func multiplying(by: NSDecimalNumber)`

Returns a new `NSDecimalNumber` object whose value is the value of the receiver multiplied by that of another given `NSDecimalNumber` object.

`func dividing(by: NSDecimalNumber)`

Returns a new `NSDecimalNumber` object whose value is the value of the receiver divided by that of another given `NSDecimalNumber` object.

`func raising(toPower: Int)`

Returns a new `NSDecimalNumber` object whose value is the value of the receiver raised to a given power.

`func multiplying(byPowerOf10: Int16)`

Multiplies the receiver by 10^`power` and returns the product, a newly created `NSDecimalNumber` object.

`func adding(NSDecimalNumber, withBehavior: NSDecimalNumberBehaviors?)`

Adds `decimalNumber` to the receiver and returns the sum, a newly created `NSDecimalNumber` object.

`func subtracting(NSDecimalNumber, withBehavior: NSDecimalNumberBehaviors?)`

Subtracts `decimalNumber` from the receiver and returns the difference, a newly created `NSDecimalNumber` object.

`func multiplying(by: NSDecimalNumber, withBehavior: NSDecimalNumberBehaviors?)`

Multiplies the receiver by `decimalNumber` and returns the product, a newly created `NSDecimalNumber` object.

`func dividing(by: NSDecimalNumber, withBehavior: NSDecimalNumberBehaviors?)`

Divides the receiver by `decimalNumber` and returns the quotient, a newly created `NSDecimalNumber` object.

`func raising(toPower: Int, withBehavior: NSDecimalNumberBehaviors?)`

Raises the receiver to `power` and returns the result, a newly created `NSDecimalNumber` object.

`func multiplying(byPowerOf10: Int16, withBehavior: NSDecimalNumberBehaviors?)`

Multiplies the receiver by 10^`power` and returns the product, a newly created `NSDecimalNumber` object.

### Rounding Off

`func rounding(accordingToBehavior: NSDecimalNumberBehaviors?)`

Rounds the receiver off in the way specified by `behavior` and returns the result, a newly created `NSDecimalNumber` object.

### Accessing the Value

`var decimalValue: Decimal`

The decimal number’s value, expressed as an `Decimal` structure.

`var doubleValue: Double`

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

`func description(withLocale: Any?)`

Returns a string, specified according to a given locale, that represents the contents of the receiver.

`var objCType: UnsafePointer<Int8>`

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

### Managing Behavior

`class var defaultBehavior: NSDecimalNumberBehaviors`

Returns the way arithmetic methods, like `adding(_:)`, round off and handle error conditions.

### Comparing Decimal Numbers

`func compare(NSNumber)`

Returns an `NSComparisonResult` value that indicates the numerical ordering of the receiver and another given `NSDecimalNumber` object.

### Getting Maximum and Minimum Possible Values

`class var maximum: NSDecimalNumber`

Returns the largest possible value of an `NSDecimalNumber` object.

`class var minimum: NSDecimalNumber`

Returns the smallest possible value of an `NSDecimalNumber` object.

### Constants

NSDecimalNumber Exception Names

Names of the various exceptions raised by `NSDecimalNumber` to indicate computational errors.