Structure

# Decimal

A structure representing a base-10 number.

## Topics

### Creating an Empty Decimal

`init()`

Creates a decimal initialized to `0`.

### Creating a Decimal from a Floating Point Number

`init(Double)`

Creates and initializes a decimal with the provided floating point value.

`init(floatLiteral: Double)`

Creates and initializes a decimal with the provided floating point value.

### Creating a Decimal from an Integer

`init?<T>(exactly: T)`

Creates a new decimal value exactly representing the provided integer.

`init(Int)`

Creates and initializes a decimal with the provided integer value.

`init(Int8)`

Creates and initializes a decimal with the provided integer value.

`init(Int16)`

Creates and initializes a decimal with the provided integer value.

`init(Int32)`

Creates and initializes a decimal with the provided integer value.

`init(Int64)`

Creates and initializes a decimal with the provided integer value.

`init(integerLiteral: Int)`

Creates and initializes a decimal with the provided integer value.

### Creating a Decimal from an Unsigned Integer

`init(UInt)`

Creates and initializes a decimal with the provided unsigned integer value.

`init(UInt8)`

Creates and initializes a decimal with the provided unsigned integer value.

`init(UInt16)`

Creates and initializes a decimal with the provided unsigned integer value.

`init(UInt32)`

Creates and initializes a decimal with the provided unsigned integer value.

`init(UInt64)`

Creates and initializes a decimal with the provided unsigned integer value.

### Creating a Decimal from Another Decimal

`init(signOf: Decimal, magnitudeOf: Decimal)`

Creates and initializes a decimal with the sign and magnitude of the given decimals.

### Converting Between Decimals and Strings

`func NSDecimalString(UnsafePointer<Decimal>, Any?) -> String`

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

### Performing Arithmetic

`static func *= (inout Decimal, Decimal)`

Multiplies two decimal numbers, storing the result in the first number.

`static func += (inout Decimal, Decimal)`

Adds two decimal numbers, storing the result in the first number.

`static func - (Decimal, Decimal) -> Decimal`

Subtracts one decimal number from another.

`static func -= (inout Decimal, Decimal)`

Subtracts one decimal number from another, storing the result in the first number.

`static func / (Decimal, Decimal) -> Decimal`

Divides one decimal number by another.

`static func /= (inout Decimal, Decimal)`

Divides one decimal number by another, storing the result in the first number.

`func pow(Decimal, Int) -> Decimal`

Returns a decimal number raised to a given power.

`func negate()`

Negates this decimal.

### Getting a Decimal's Characteristics

`var exponent: Int`

The exponent of the decimal.

`var significand: Decimal`

The significand of the decimal.

`var magnitude: Decimal`

The magnitude of this decimal.

`var isCanonical: Bool`

A Boolean value indicating whether the representation of this decimal is canonical.

`var isFinite: Bool`

A Boolean value indicating whether this decimal is zero, subnormal, or normal (not infinity or NaN).

`var isInfinite: Bool`

A Boolean value indicating whether this decimal is infinity.

`var isNaN: Bool`

A Boolean value indicating whether this decimal is NaN.

`var isNormal: Bool`

A Boolean value indicating whether this decimal is normal (not zero, subnormal, infinity, or NaN).

`var isSignMinus: Bool`

A Boolean value indicating whether this decimal has a negative sign.

`var isSignaling: Bool`

A Boolean value indicating whether this decimal is a signaling NaN.

`var isSignalingNaN: Bool`

A Boolean value indicating whether this decimal is a signaling NaN.

`var isSubnormal: Bool`

A Boolean value indicating whether this decimal is subnormal.

`var isZero: Bool`

A Boolean value indicating whether this value is zero.

`var nextDown: Decimal`

The greatest representable value that is less than this decimal.

`var nextUp: Decimal`

The least representable value that is greater than this decimal.

`var ulp: Decimal`

The unit in the last place of the decimal.

### Getting Particular Decimals

`static let greatestFiniteMagnitude: Decimal`

The decimal that contains the largest possible non-infinite magnitude for the underlying representation.

`static let leastFiniteMagnitude: Decimal`

The decimal that contains the smallest possible non-infinite magnitude for the underlying representation.

`static let leastNonzeroMagnitude: Decimal`

The decimal value that represents the smallest possible non-zero value for the underlying representation.

`static let leastNormalMagnitude: Decimal`

The decimal value that represents the smallest possible normal magnitude for the underlying representation.

`static let pi: Decimal`

The mathematical constant pi.

`static var nan: Decimal`

The value that represents "not a number."

`static var quietNaN: Decimal`

A quiet representation of not-a-number.

`static var radix: Int`

The radix used by decimal numbers.

`var NSDecimalNoScale: Int32`

Specifies that the number of digits allowed after the decimal separator in a decimal number should not be limited.

### Comparing Decimals

`static func < (Decimal, Decimal) -> Bool`

Returns a Boolean value indicating whether one decimal number is strictly less than another.

`static func == (Decimal, Decimal) -> Bool`

Returns a Boolean value indicating whether two decimal numbers are equal.

`func isEqual(to: Decimal) -> Bool`

Indicates whether this decimal is equal to the specified one.

`func isLess(than: Decimal) -> Bool`

Indicates whether this decimal is less than the specified one.

`func isLessThanOrEqualTo(Decimal) -> Bool`

Indicates whether this decimal is less than or equal to the specified one.

`func isTotallyOrdered(belowOrEqualTo: Decimal) -> Bool`

Returns a Boolean value indicating whether this instance should precede the given value in an ascending sort.

`func distance(to: Decimal) -> Decimal`

Returns the distance from this value to the specified value.

`func advanced(by: Decimal) -> Decimal`

Returns a new value advanced by the given distance.

### Encoding and Decoding

`func encode(to: Encoder)`

Encodes this decimal value into the given encoder.

`init(from: Decoder)`

Creates a new decimal value by decoding from the given decoder.

### Describing a Decimal

`var description: String`

A textual description of the decimal.

`var hashValue: Int`

The computed hash value for the decimal.

### Using Reference Types

`class NSDecimalNumber`

An object for representing and performing arithmetic on base-10 numbers that bridges to `Decimal`; use `NSDecimalNumber` when you need reference semantics or other Foundation-specific behavior.

## Relationships

### Numbers

`struct Int`

A signed integer value type.

`struct Double`

A double-precision, floating-point value type.

`class NumberFormatter`

A formatter that converts between numeric values and their textual representations.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.