<!--
{
  "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/Decimal",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@SA@NSDecimal"
  },
  "title" : "Decimal"
}
-->

# Decimal

A structure representing a base-10 number.

```
struct Decimal
```

## Topics

### Creating an empty decimal

[`init()`](/documentation/Foundation/Decimal/init())

Creates a decimal initialized to `0`.

### Creating a decimal from components

[`init(sign:exponent:significand:)`](/documentation/Foundation/Decimal/init(sign:exponent:significand:))

Creates a decimal initialized with the given sign, exponent, and significand.

  <doc:decimal/1407961-init>

### Creating a decimal from a floating point number

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-6wgru)

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

[`init(floatLiteral:)`](/documentation/Foundation/Decimal/init(floatLiteral:))

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

### Creating a decimal from an integer

[`init(exactly:)`](/documentation/Foundation/Decimal/init(exactly:))

Creates a new decimal value exactly representing the provided integer.

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-2tcho)

Creates and initializes a decimal with the provided integer value.

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-4gk29)

Creates and initializes a decimal with the provided integer value.

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-5aznh)

Creates and initializes a decimal with the provided integer value.

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-7dmlc)

Creates and initializes a decimal with the provided integer value.

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-7a033)

Creates and initializes a decimal with the provided integer value.

[`init(integerLiteral:)`](/documentation/Foundation/Decimal/init(integerLiteral:))

Creates and initializes a decimal with the provided integer value.

### Creating a decimal from an unsigned integer

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-2lxxy)

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

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-4gbgq)

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

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-9lio1)

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

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-9okou)

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

[`init(_:)`](/documentation/Foundation/Decimal/init(_:)-43cx6)

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

### Creating a decimal from another decimal

[`init(signOf:magnitudeOf:)`](/documentation/Foundation/Decimal/init(signOf:magnitudeOf:))

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

[`NSDecimalCopy`](/documentation/Foundation/NSDecimalCopy(_:_:))

Copies the value of a decimal number.

### Creating a decimal by parsing a string

[`init(_:format:lenient:)`](/documentation/Foundation/Decimal/init(_:format:lenient:)-6fk71)

Creates and initializes a decimal by parsing a string according to the provided format style.

[`init(_:format:lenient:)`](/documentation/Foundation/Decimal/init(_:format:lenient:)-8t5o2)

Creates and initializes a decimal by parsing a string according to the provided currency format style.

[`init(_:format:lenient:)`](/documentation/Foundation/Decimal/init(_:format:lenient:)-3u6o6)

Creates and initializes a percentage decimal by parsing a string according to the provided format style.

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

Creates and initializes a decimal by parsing a string according to the provided locale’s conventions.

[`init(_:strategy:)`](/documentation/Foundation/Decimal/init(_:strategy:))

Creates and initializes a decimal by parsing an arbitrary type according to the provided parse strategy.

[`ParseStrategy`](/documentation/Foundation/Decimal/ParseStrategy)

A parse strategy for creating decimal values from formatted strings.

### Performing arithmetic

[`pow(_:_:)`](/documentation/Foundation/pow(_:_:))

Returns a decimal number raised to a given power.

### Performing arithmetic using references

[`NSDecimalCompact`](/documentation/Foundation/NSDecimalCompact(_:))

Compacts the decimal structure for efficiency.

[`NSDecimalAdd`](/documentation/Foundation/NSDecimalAdd(_:_:_:_:))

Adds two decimal values.

[`NSDecimalSubtract`](/documentation/Foundation/NSDecimalSubtract(_:_:_:_:))

Subtracts one decimal value from another.

[`NSDecimalDivide`](/documentation/Foundation/NSDecimalDivide(_:_:_:_:))

Divides one decimal value by another.

[`NSDecimalMultiply`](/documentation/Foundation/NSDecimalMultiply(_:_:_:_:))

Multiplies two decimal numbers together.

[`NSDecimalMultiplyByPowerOf10`](/documentation/Foundation/NSDecimalMultiplyByPowerOf10(_:_:_:_:))

Multiplies a decimal by the specified power of 10.

[`NSDecimalRound`](/documentation/Foundation/NSDecimalRound(_:_:_:_:))

Rounds off the decimal value.

[`NSDecimalPower`](/documentation/Foundation/NSDecimalPower(_:_:_:_:))

Raises the decimal value to the specified power.

[`NSDecimalNormalize`](/documentation/Foundation/NSDecimalNormalize(_:_:_:))

Normalizes the internal format of two decimal numbers to simplify later operations.

[`RoundingMode`](/documentation/Foundation/Decimal/RoundingMode)

An alias for an enumeration that specifies possible rounding modes.

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

These constants specify rounding behaviors.

[`CalculationError`](/documentation/Foundation/Decimal/CalculationError)

An alias for a type that specifies possible calculation errors.

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

Calculation error constants used to describe an error in [`exceptionDuringOperation(_:error:leftOperand:rightOperand:)`](/documentation/Foundation/NSDecimalNumberBehaviors/exceptionDuringOperation(_:error:leftOperand:rightOperand:)).

### Getting a decimal’s characteristics

[`sign`](/documentation/Foundation/Decimal/sign)

The sign of the decimal.

[`exponent`](/documentation/Foundation/Decimal/exponent)

The exponent of the decimal.

[`significand`](/documentation/Foundation/Decimal/significand)

The significand of the decimal.

[`magnitude`](/documentation/Foundation/Decimal/magnitude)

The magnitude of this decimal.

[`floatingPointClass`](/documentation/Foundation/Decimal/floatingPointClass)

The IEEE 754 class of this type.

[`isCanonical`](/documentation/Foundation/Decimal/isCanonical)

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

[`isFinite`](/documentation/Foundation/Decimal/isFinite)

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

[`isInfinite`](/documentation/Foundation/Decimal/isInfinite)

A Boolean value indicating whether this decimal is infinity.

[`isNaN`](/documentation/Foundation/Decimal/isNaN)

A Boolean value indicating whether this decimal is NaN.

[`isNormal`](/documentation/Foundation/Decimal/isNormal)

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

[`isSignMinus`](/documentation/Foundation/Decimal/isSignMinus)

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

[`isSignaling`](/documentation/Foundation/Decimal/isSignaling)

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

[`isSignalingNaN`](/documentation/Foundation/Decimal/isSignalingNaN)

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

[`isSubnormal`](/documentation/Foundation/Decimal/isSubnormal)

A Boolean value indicating whether this decimal is subnormal.

[`isZero`](/documentation/Foundation/Decimal/isZero)

A Boolean value indicating whether this value is zero.

[`nextDown`](/documentation/Foundation/Decimal/nextDown)

The greatest representable value that is less than this decimal.

[`nextUp`](/documentation/Foundation/Decimal/nextUp)

The least representable value that is greater than this decimal.

[`ulp`](/documentation/Foundation/Decimal/ulp)

The unit in the last place of the decimal.

### Getting particular decimals

[`greatestFiniteMagnitude`](/documentation/Foundation/Decimal/greatestFiniteMagnitude)

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

[`leastFiniteMagnitude`](/documentation/Foundation/Decimal/leastFiniteMagnitude)

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

[`leastNonzeroMagnitude`](/documentation/Foundation/Decimal/leastNonzeroMagnitude)

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

[`leastNormalMagnitude`](/documentation/Foundation/Decimal/leastNormalMagnitude)

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

[`pi`](/documentation/Foundation/Decimal/pi)

The mathematical constant pi.

[`nan`](/documentation/Foundation/Decimal/nan)

The value that represents “not a number.”

[`quietNaN`](/documentation/Foundation/Decimal/quietNaN)

A quiet representation of not-a-number.

[`radix`](/documentation/Foundation/Decimal/radix)

The radix used by decimal numbers.

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

The maximum size of [`Decimal`](/documentation/Foundation/Decimal).

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

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

### Formatting decimals

[`formatted()`](/documentation/Foundation/Decimal/formatted())

Formats the decimal using a default localized format style.

[`formatted(_:)`](/documentation/Foundation/Decimal/formatted(_:))

Formats the decimal using the provided format style.

[`FormatStyle`](/documentation/Foundation/Decimal/FormatStyle)

A structure that converts between decimal values and their textual representations.

### Converting between decimals and strings

[`NSDecimalString`](/documentation/Foundation/NSDecimalString(_:_:))

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

### Working with charts

  <doc:decimal/3974139-init>

  <doc:decimal/3974140-primitiveplottable>

  <doc:decimal/primitiveplottable>

### Comparing decimals

[`isEqual(to:)`](/documentation/Foundation/Decimal/isEqual(to:))

Indicates whether this decimal is equal to the specified one.

[`isLess(than:)`](/documentation/Foundation/Decimal/isLess(than:))

Indicates whether this decimal is less than the specified one.

[`isLessThanOrEqualTo(_:)`](/documentation/Foundation/Decimal/isLessThanOrEqualTo(_:))

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

[`isTotallyOrdered(belowOrEqualTo:)`](/documentation/Foundation/Decimal/isTotallyOrdered(belowOrEqualTo:))

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

[`distance(to:)`](/documentation/Foundation/Decimal/distance(to:))

Returns the distance from this value to the specified value.

[`advanced(by:)`](/documentation/Foundation/Decimal/advanced(by:))

Returns a new value advanced by the given distance.

[`NSDecimalCompare`](/documentation/Foundation/NSDecimalCompare(_:_:))

Compares two decimal values.

### Using reference types

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

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

### Supporting Types

[`FormatStyle`](/documentation/Foundation/Decimal/FormatStyle)

A structure that converts between decimal values and their textual representations.

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`Escapable`](/documentation/Swift/Escapable)

[`Copyable`](/documentation/Swift/Copyable)

[`ExpressibleByFloatLiteral`](/documentation/Swift/ExpressibleByFloatLiteral)

[`ConvertibleToGeneratedContent`](/documentation/FoundationModels/ConvertibleToGeneratedContent)

[`PromptRepresentable`](/documentation/FoundationModels/PromptRepresentable)

[`Hashable`](/documentation/Swift/Hashable)

[`Numeric`](/documentation/Swift/Numeric)

[`Encodable`](/documentation/Swift/Encodable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Comparable`](/documentation/Swift/Comparable)

[`AdditiveArithmetic`](/documentation/Swift/AdditiveArithmetic)

[`Strideable`](/documentation/Swift/Strideable)

[`ExpressibleByIntegerLiteral`](/documentation/Swift/ExpressibleByIntegerLiteral)

[`Generable`](/documentation/FoundationModels/Generable)

[`InstructionsRepresentable`](/documentation/FoundationModels/InstructionsRepresentable)

[`Sendable`](/documentation/Swift/Sendable)

[`Plottable`](/documentation/Charts/Plottable)

[`SignedNumeric`](/documentation/Swift/SignedNumeric)

[`Decodable`](/documentation/Swift/Decodable)

[`ConvertibleFromGeneratedContent`](/documentation/FoundationModels/ConvertibleFromGeneratedContent)

---

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)