<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Decimal/ParseStrategy",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So9NSDecimala10FoundationE13ParseStrategyV"
  },
  "title" : "Decimal.ParseStrategy"
}
-->

# Decimal.ParseStrategy

A parse strategy for creating decimal values from formatted strings.

```
struct ParseStrategy<Format> where Format : FormatStyle, Format.FormatInput == Decimal
```

## Overview

Create an explicit [`Decimal.ParseStrategy`](/documentation/Foundation/Decimal/ParseStrategy) to parse mulitple strings according to the same parse strategy. In the following example, `usCurrencyStrategy` is a [`Decimal.ParseStrategy`](/documentation/Foundation/Decimal/ParseStrategy) that uses US dollars and the `en_US` locale’s conventions for number formatting. The example then uses this strategy to parse an array of strings, some of which represent valid US currency values.

```swift
let usCurrencyStrategy: Decimal.ParseStrategy =
Decimal.FormatStyle.Currency(code: "USD",
                             locale: Locale(identifier: "en_US"))
.parseStrategy
let currencyValues = ["$100.11", "$1,000.22", "$10,000.33", "€100.44"]
let parsedValues = currencyValues.map { try? usCurrencyStrategy.parse($0) } // [Optional(100.11), Optional(1000.22), Optional(10000.33), nil]
```

You don’t need to instantiate a parse strategy variable to parse a single string. Instead, use the [`init(_:format:lenient:)`](/documentation/Foundation/Decimal/init(_:format:lenient:)-3u6o6) initializer, which takes a source <doc://com.apple.documentation/documentation/Swift/String> and a `format` parameter to parse the string according to the provided [`Decimal.FormatStyle`](/documentation/Foundation/Decimal/FormatStyle). The following example parses a string that represents a currency value in US dollars.

```swift
let formattedUSDollars = "$1,234.56"
let parsedUSDollars = try? Decimal(formattedUSDollars, format: .currency(code: "USD")
    .locale(Locale(identifier: "en_US"))) // 1234.56
```

Decimal also has an [`init(_:strategy:)`](/documentation/Foundation/Decimal/init(_:strategy:)) initializer, if it’s more convenient to pass a [`Decimal.ParseStrategy`](/documentation/Foundation/Decimal/ParseStrategy) instance rather than implicitly derive a strategy from a [`Decimal.FormatStyle`](/documentation/Foundation/Decimal/FormatStyle).

## Topics

### Creating a decimal parse strategy

[`init(format: Format, lenient: Bool)`](/documentation/Foundation/Decimal/ParseStrategy/init(format:lenient:)-46ix2)

Creates a parse strategy instance using the specified decimal format style.

[`init(format: Format, lenient: Bool)`](/documentation/Foundation/Decimal/ParseStrategy/init(format:lenient:)-22h06)

Creates a parse strategy instance using the specified decimal currency format style.

[`init(format: Format, lenient: Bool)`](/documentation/Foundation/Decimal/ParseStrategy/init(format:lenient:)-36ja3)

Creates a parse strategy instance using the specified decimal percentage format style.

### Parsing strings

[`func parse(String) throws -> Format.FormatInput`](/documentation/Foundation/Decimal/ParseStrategy/parse(_:))

Parses a decimal string in accordance with this strategy and returns the parsed value.

### Accessing strategy properties

[`var formatStyle: Format`](/documentation/Foundation/Decimal/ParseStrategy/formatStyle)

The format style this strategy uses when parsing strings.

[`var lenient: Bool`](/documentation/Foundation/Decimal/ParseStrategy/lenient)

A Boolean value that indicates whether parsing allows any discrepencies in the expected format.

### Applying date-parsing strategies

### Supporting types

### Default Implementations

[ParseStrategy Implementations](/documentation/Foundation/Decimal/ParseStrategy/ParseStrategy-Implementations)

## Relationships

### Conforms To

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

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

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

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

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

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

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

---

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)