Class

NSDecimal​Number

NSDecimal​Number, 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.

Overview

Symbols

Creating a Decimal Number

class var one:​ NSDecimal​Number

Returns an NSDecimal​Number object equivalent to the number 1.0.

class var zero:​ NSDecimal​Number

Returns an NSDecimal​Number object equivalent to the number 0.0.

class var not​ANumber:​ NSDecimal​Number

Returns an NSDecimal​Number object that specifies no number.

Initializing a Decimal Number

init(decimal:​ Decimal)

Returns an NSDecimal​Number object initialized to represent a given decimal.

init(mantissa:​ UInt64, exponent:​ Int16, is​Negative:​ Bool)

Returns an NSDecimal​Number object initialized using the given mantissa, exponent, and sign.

init(string:​ String?)

Returns an NSDecimal​Number object initialized so that its value is equivalent to that in a given numeric string.

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

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

Performing Arithmetic

func adding(NSDecimal​Number)

Returns a new NSDecimal​Number object whose value is the sum of the receiver and another given NSDecimal​Number object.

func subtracting(NSDecimal​Number)

Returns a new NSDecimal​Number object whose value is that of another given NSDecimal​Number object subtracted from the value of the receiver.

func multiplying(by:​ NSDecimal​Number)

Returns a new NSDecimal​Number object whose value is the value of the receiver multiplied by that of another given NSDecimal​Number object.

func dividing(by:​ NSDecimal​Number)

Returns a new NSDecimal​Number object whose value is the value of the receiver divided by that of another given NSDecimal​Number object.

func raising(to​Power:​ Int)

Returns a new NSDecimal​Number object whose value is the value of the receiver raised to a given power.

func multiplying(by​Power​Of10:​ Int16)

Multiplies the receiver by 10^power and returns the product, a newly created NSDecimal​Number object.

func adding(NSDecimal​Number, with​Behavior:​ NSDecimal​Number​Behaviors?)

Adds decimal​Number to the receiver and returns the sum, a newly created NSDecimal​Number object.

func subtracting(NSDecimal​Number, with​Behavior:​ NSDecimal​Number​Behaviors?)

Subtracts decimal​Number from the receiver and returns the difference, a newly created NSDecimal​Number object.

func multiplying(by:​ NSDecimal​Number, with​Behavior:​ NSDecimal​Number​Behaviors?)

Multiplies the receiver by decimal​Number and returns the product, a newly created NSDecimal​Number object.

func dividing(by:​ NSDecimal​Number, with​Behavior:​ NSDecimal​Number​Behaviors?)

Divides the receiver by decimal​Number and returns the quotient, a newly created NSDecimal​Number object.

func raising(to​Power:​ Int, with​Behavior:​ NSDecimal​Number​Behaviors?)

Raises the receiver to power and returns the result, a newly created NSDecimal​Number object.

func multiplying(by​Power​Of10:​ Int16, with​Behavior:​ NSDecimal​Number​Behaviors?)

Multiplies the receiver by 10^power and returns the product, a newly created NSDecimal​Number object.

Rounding Off

func rounding(according​To​Behavior:​ NSDecimal​Number​Behaviors?)

Rounds the receiver off in the way specified by behavior and returns the result, a newly created NSDecimal​Number object.

Accessing the Value

var decimal​Value:​ Decimal

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

var double​Value:​ Double

The decimal number’s closest approximate double value.

func description(with​Locale:​ Any?)

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

var obj​CType:​ Unsafe​Pointer<Int8>

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

Managing Behavior

class var default​Behavior:​ NSDecimal​Number​Behaviors

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

Comparing Decimal Numbers

func compare(NSNumber)

Returns an NSComparison​Result value that indicates the numerical ordering of the receiver and another given NSDecimal​Number object.

Getting Maximum and Minimum Possible Values

class var maximum:​ NSDecimal​Number

Returns the largest possible value of an NSDecimal​Number object.

class var minimum:​ NSDecimal​Number

Returns the smallest possible value of an NSDecimal​Number object.

Constants

NSDecimal​Number Exception Names

Names of the various exceptions raised by NSDecimal​Number to indicate computational errors.