<!--
{
  "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/FormatStyle/precision(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So9NSDecimala10FoundationE11FormatStyleV9precisionyAeC06NumbercD13ConfigurationO9PrecisionVF"
  },
  "title" : "precision(_:)"
}
-->

# precision(_:)

Modifies the format style to use the specified precision.

```
func precision(_ p: Decimal.FormatStyle.Configuration.Precision) -> Decimal.FormatStyle
```

## Parameters

`p`

The precision to apply to the format style.

## Return Value

A decimal format style modified to use the specified precision.

## Discussion

The [`NumberFormatStyleConfiguration.Precision`](/documentation/Foundation/NumberFormatStyleConfiguration/Precision) type lets you specify fixed numbers of digits to show for a number’s integer and fractional parts. You can also set a fixed number of significant digits.

The following example creates a default [`Decimal.FormatStyle`](/documentation/Foundation/Decimal/FormatStyle) for the `en_US` locale, and a second style that uses a maximum of four significant digits. It then applies each style to an array of decimal values. The formatting applied by the modified style truncates precision to `0` after the fourth most-significant digit.

```swift
let defaultStyle = Decimal.FormatStyle(locale: Locale(identifier: "en_US"))
let precisionStyle = defaultStyle.precision(.significantDigits(1...4))
let nums: [Decimal] = [123.1, 1234.1, 12345.1, 123456.1, 1234567.1]
let defaultNums = nums.map { defaultStyle.format($0) } // ["123.1", "1,234.1", "12,345.1", "123,456.1", "1,234,567.1"]
let precisionNums = nums.map { precisionStyle.format($0) } // ["123.1", "1,234", "12,350", "123,500", "1,235,000"]
```

---

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)