<!--
{
  "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/IntegerFormatStyle",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation18IntegerFormatStyleV"
  },
  "title" : "IntegerFormatStyle"
}
-->

# IntegerFormatStyle

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

```
struct IntegerFormatStyle<Value> where Value : BinaryInteger
```

## Overview

Instances of [`IntegerFormatStyle`](/documentation/Foundation/IntegerFormatStyle) create localized, human-readable text from <doc://com.apple.documentation/documentation/Swift/BinaryInteger> numbers and parse string representations of numbers into instances of <doc://com.apple.documentation/documentation/Swift/BinaryInteger> types. All of the Swift standard library’s integer types, such as <doc://com.apple.documentation/documentation/Swift/Int> and <doc://com.apple.documentation/documentation/Swift/UInt32>, conform to <doc://com.apple.documentation/documentation/Swift/BinaryInteger>, and therefore work with this format style.

[`IntegerFormatStyle`](/documentation/Foundation/IntegerFormatStyle) includes two nested types, [`IntegerFormatStyle.Percent`](/documentation/Foundation/IntegerFormatStyle/Percent) and [`IntegerFormatStyle.Currency`](/documentation/Foundation/IntegerFormatStyle/Currency), for working with percentages and currencies. Each format style includes a configuration that determines how it represents numeric values, for things like grouping, displaying signs, and variant presentations like scientific notation. [`IntegerFormatStyle`](/documentation/Foundation/IntegerFormatStyle) and [`IntegerFormatStyle.Percent`](/documentation/Foundation/IntegerFormatStyle/Percent) include a [`NumberFormatStyleConfiguration`](/documentation/Foundation/NumberFormatStyleConfiguration), and [`IntegerFormatStyle.Currency`](/documentation/Foundation/IntegerFormatStyle/Currency) includes a [`CurrencyFormatStyleConfiguration`](/documentation/Foundation/CurrencyFormatStyleConfiguration). You can customize numeric formatting for a style by adjusting its backing configuration. The system automatically caches unique configurations of a format style to enhance performance.

> Note:
> Foundation provides another format style type, ``doc://com.apple.foundation/documentation/Foundation/FloatingPointFormatStyle``, for working with numbers that conform to <doc://com.apple.documentation/documentation/Swift/BinaryFloatingPoint>. For Foundation’s ``doc://com.apple.foundation/documentation/Foundation/Decimal`` type, use ``doc://com.apple.foundation/documentation/Foundation/Decimal/FormatStyle``.

### Formatting integers

Use the <doc://com.apple.documentation/documentation/Swift/BinaryInteger/formatted()> method to create a string representation of an integer using the default [`IntegerFormatStyle`](/documentation/Foundation/IntegerFormatStyle) configuration.

```swift
let formattedDefault = 123456.formatted()
// formattedDefault is "123,456" in en_US locale.
// Other locales may use different separator and grouping behavior.
```

You can specify a format style by providing an argument to the <doc://com.apple.documentation/documentation/Swift/BinaryInteger/formatted(_:)-73k3e> method. The following example shows the number `12345` represented in each of the available styles, in the `en_US` locale:

```swift
let number = 123456

let formattedNumber = number.formatted(.number)
// formattedNumber is "123,456".

let formattedPercent = number.formatted(.percent)
// formattedPercent is "123,456%".

let formattedCurrency = number.formatted(.currency(code: "USD"))
// formattedCurrency is "$123,456.00".
```

Each style provides methods for updating its numeric configuration, including the number of significant digits, grouping length, and more. You can specify a numeric configuration by calling as many of these methods as you need in any order you choose. The following example shows the same number with default and custom configurations:

```swift
let exampleNumber = 123456

let defaultFormatting = exampleNumber.formatted(.number)
// defaultFormatting is "125 000" for the "fr_FR" locale
// defaultFormatting is "125000" for the "jp_JP" locale
// defaultFormatting is "125,000" for the "en_US" locale

let customFormatting = exampleNumber.formatted(
    .number
    .grouping(.never)
    .sign(strategy: .always()))
// customFormatting is "+123456"
```

### Creating an integer format style instance

The previous examples use static factory methods like [`number`](/documentation/Foundation/FormatStyle/number-7fxvo) to create format styles within the call to the <doc://com.apple.documentation/documentation/Swift/BinaryInteger/formatted(_:)-73k3e> method. You can also create an [`IntegerFormatStyle`](/documentation/Foundation/IntegerFormatStyle) instance and use it to repeatedly format different values with the [`format(_:)`](/documentation/Foundation/IntegerFormatStyle/format(_:)) method:

```swift
let percentFormatStyle = IntegerFormatStyle<Int>.Percent()

percentFormatStyle.format(50) // "50%"
percentFormatStyle.format(85) // "85%"
percentFormatStyle.format(100) // "100%"
```

### Parsing integers

You can use [`IntegerFormatStyle`](/documentation/Foundation/IntegerFormatStyle) to parse strings into integer values. You can define the format style within the type’s initializer or pass in a format style you create prior to calling the method, as shown here:

```swift
let price = try? Int("$123,456",
                     format: .currency(code: "USD")) // 123456

let priceFormatStyle = IntegerFormatStyle<Int>.Currency(code: "USD")
let salePrice = try? Int("$120,000",
                          format: priceFormatStyle) // 120000
```

### Matching regular expressions

Along with parsing numeric values in strings, you can use the Swift regular expression domain-specific language to match and capture numeric substrings. The following example defines a currency format style to match and capture a currency value using US dollars and `en_US` numeric conventions. The rest of the regular expression ignores any characters prior to a `": "` sequence that precedes the currency substring.

```swift
import RegexBuilder

let source = "Payment due: $123,456"
let matcher = Regex {
    OneOrMore(.any)
    ": "
    Capture {
        One(.localizedIntegerCurrency(code: Locale.Currency("USD"),
                                      locale: Locale(identifier: "en_US")))
    }
}
let match = source.firstMatch(of: matcher)
let localizedInteger = match?.1 // 123456
```

## Topics

### Creating an integer format style

[`init(locale:)`](/documentation/Foundation/IntegerFormatStyle/init(locale:))

Creates an integer format style that uses the given locale.

### Formatting integer values

[`format(_:)`](/documentation/Foundation/IntegerFormatStyle/format(_:))

Formats an integer, using this style.

### Customizing style behavior

[`decimalSeparator(strategy:)`](/documentation/Foundation/IntegerFormatStyle/decimalSeparator(strategy:))

Modifies the format style to use the specified decimal separator display strategy.

[`grouping(_:)`](/documentation/Foundation/IntegerFormatStyle/grouping(_:))

Modifies the format style to use the specified grouping.

[`notation(_:)`](/documentation/Foundation/IntegerFormatStyle/notation(_:))

Modifies the format style to use the specified notation.

[`precision(_:)`](/documentation/Foundation/IntegerFormatStyle/precision(_:))

Modifies the format style to use the specified precision.

[`rounded(rule:increment:)`](/documentation/Foundation/IntegerFormatStyle/rounded(rule:increment:))

Modifies the format style to use the specified rounding rule and increment.

[`scale(_:)`](/documentation/Foundation/IntegerFormatStyle/scale(_:))

Modifies the format style to use the specified scale.

[`sign(strategy:)`](/documentation/Foundation/IntegerFormatStyle/sign(strategy:))

Modifies the format style to use the specified sign display strategy for displaying or omitting sign symbols.

[`IntegerFormatStyle.Configuration`](/documentation/Foundation/IntegerFormatStyle/Configuration)

The type the format style uses for configuration settings.

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

Configuration settings for formatting numbers of different types.

### Acessing style locale

[`locale`](/documentation/Foundation/IntegerFormatStyle/locale)

The locale of the format style.

### Applying currency styles

[`IntegerFormatStyle.Currency`](/documentation/Foundation/IntegerFormatStyle/Currency)

A format style that converts between integer currency values and their textual representations.

### Applying measurement styles

[`Measurement.FormatStyle`](/documentation/Foundation/Measurement/FormatStyle)

A type that provides localized representations of measurements.

### Applying list styles

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

A type that formats lists of items with a separator and conjunction appropriate for a given locale.

### Creating attributed strings

[`attributed`](/documentation/Foundation/IntegerFormatStyle/attributed-swift.property)

An attributed format style based on the integer format style.

[`IntegerFormatStyle.Attributed`](/documentation/Foundation/IntegerFormatStyle/Attributed-swift.struct)

A format style that converts integers into attributed strings.

### Parsing integers

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

A parse strategy for creating integer values from formatted strings.

### Supporting types

[`IntegerFormatStyle.Currency`](/documentation/Foundation/IntegerFormatStyle/Currency)

A format style that converts between integer currency values and their textual representations.

[`IntegerFormatStyle.Percent`](/documentation/Foundation/IntegerFormatStyle/Percent)

A format style that converts between integer percentage values and their textual representations.



---

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)