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

# FloatingPointFormatStyle

A structure that converts between floating-point values and their textual representations.

```
struct FloatingPointFormatStyle<Value> where Value : BinaryFloatingPoint
```

## Overview

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

[`FloatingPointFormatStyle`](/documentation/Foundation/FloatingPointFormatStyle) includes two nested types, [`FloatingPointFormatStyle.Percent`](/documentation/Foundation/FloatingPointFormatStyle/Percent) and [`FloatingPointFormatStyle.Currency`](/documentation/Foundation/FloatingPointFormatStyle/Currency), for working with percentages and currencies, respectively. 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. [`FloatingPointFormatStyle`](/documentation/Foundation/FloatingPointFormatStyle) and [`FloatingPointFormatStyle.Percent`](/documentation/Foundation/FloatingPointFormatStyle/Percent) include a [`NumberFormatStyleConfiguration`](/documentation/Foundation/NumberFormatStyleConfiguration), and [`FloatingPointFormatStyle.Currency`](/documentation/Foundation/FloatingPointFormatStyle/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/IntegerFormatStyle``, for working with numbers that conform to <doc://com.apple.documentation/documentation/Swift/BinaryInteger>. For Foundation’s ``doc://com.apple.foundation/documentation/Foundation/Decimal`` type, use ``doc://com.apple.foundation/documentation/Foundation/Decimal/FormatStyle``.

### Formatting floating-point values

Use the <doc://com.apple.documentation/documentation/Swift/BinaryFloatingPoint/formatted()> method to create a string representation of a floating-point value using the default [`FloatingPointFormatStyle`](/documentation/Foundation/FloatingPointFormatStyle) configuration.

```swift
let formattedDefault = 12345.67.formatted()
// formattedDefault is "12,345.67" in the 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/BinaryFloatingPoint/formatted(_:)-4ksqj> method. The following example shows the number `0.1` represented in each of the available styles, in the `en_US` locale:

```swift
let number = 0.1

let formattedNumber = number.formatted(.number)
// formattedNumber is "0.1".

let formattedPercent = number.formatted(.percent)
// formattedPercent is "10%".

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

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.78

let defaultFormatting = exampleNumber.formatted(.number)
// defaultFormatting is "123 456,78" for the "fr_FR" locale.
// defaultFormatting is "123,456.78" for the "en_US" locale.

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

### Creating a floating-point format style instance

The previous examples use static factory methods like [`number`](/documentation/Foundation/FormatStyle/number-8c8rj) to create format styles within the call to the <doc://com.apple.documentation/documentation/Swift/BinaryFloatingPoint/formatted(_:)-4ksqj> method. You can also create a [`FloatingPointFormatStyle`](/documentation/Foundation/FloatingPointFormatStyle) instance and use it to repeatedly format different values, with the [`format(_:)`](/documentation/Foundation/FloatingPointFormatStyle/format(_:)) method:

```swift
let percentFormatStyle = FloatingPointFormatStyle<Double>.Percent()

percentFormatStyle.format(0.5) // "50%"
percentFormatStyle.format(0.855) // "85.5%"
percentFormatStyle.format(1.0) // "100%"
```

### Parsing floating-point values

You can use [`FloatingPointFormatStyle`](/documentation/Foundation/FloatingPointFormatStyle) to parse strings into floating-point values. You can define the format style within the type’s initializer or pass in a format style created outside the function, as shown here:

```swift
let price = try? Double("$3,500.63",
                         format: .currency(code: "USD")) // 3500.63

let priceFormatStyle = FloatingPointFormatStyle<Double>.Currency(code: "USD")
let salePrice = try? Double("$731.67",
                             format: priceFormatStyle) // 731.67
```

### Matching regular expressions

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

```swift
import RegexBuilder
let source = "Percentage complete: 55.1%"
let matcher = Regex {
    OneOrMore(.any)
    ": "
    Capture {
        One(.localizedDoublePercentage(locale: Locale(identifier: "en_US")))
    }
}
let match = source.firstMatch(of: matcher)
let localizedPercentage = match?.1
print("\(localizedPercentage!)") // 0.551
```

## Topics

### Creating a floating-point format style

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

Creates a floating-point format style that uses the given locale.

### Formatting floating-point values

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

Formats a floating-point value, using this style.

### Customizing style behavior

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

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

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

Modifies the format style to use the specified grouping.

[`locale(_:)`](/documentation/Foundation/FloatingPointFormatStyle/locale(_:))

Modifies the format style to use the specified locale.

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

Modifies the format style to use the specified notation.

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

Modifies the format style to use the specified precision.

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

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

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

Modifies the format style to use the specified scale.

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

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

[`Configuration`](/documentation/Foundation/FloatingPointFormatStyle/Configuration)

The type the format style uses for configuration settings.

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

Configuration settings for formatting numbers of different types.

### Accessing style locale

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

The locale of the format style.

### Applying currency styles

[`Currency`](/documentation/Foundation/FloatingPointFormatStyle/Currency)

A format style that converts between floating-point currency values and their textual representations.

### Applying measurement styles

[`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/FloatingPointFormatStyle/attributed-swift.property)

An attributed format style based on the floating-point format style.

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

A format style that converts integers into attributed strings.

### Parsing floating-point numbers

[`parseStrategy`](/documentation/Foundation/FloatingPointFormatStyle/parseStrategy)

The parse strategy that this format style uses.

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

A parse strategy for creating floating-point values from formatted strings.

### Locating floating-point numbers with regular expressions

[`consuming(_:startingAt:in:)`](/documentation/Foundation/FloatingPointFormatStyle/consuming(_:startingAt:in:))

Process the input string within the specified bounds, beginning at the given index, and return the end position (upper bound) of the match and the produced output.

### Supporting types

[`Currency`](/documentation/Foundation/FloatingPointFormatStyle/Currency)

A format style that converts between floating-point currency values and their textual representations.

[`Percent`](/documentation/Foundation/FloatingPointFormatStyle/Percent)

A format style that converts between floating-point percentage values and their textual representations.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

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

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

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

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

---

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)