---
title: "precision(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/floatingpointformatstyle/precision(_:)"
---

# precision(_:)

Modifies the format style to use the specified precision.

## Declaration

```swift
func precision(_ p: FloatingPointFormatStyle<Value>.Configuration.Precision) -> FloatingPointFormatStyle<Value>
```

## Parameters

- `p`: The precision to apply to the format style.

## Return Value

Return Value A floating-point format style modified to use the specified precision.

## Discussion

Discussion The NumberFormatStyleConfiguration.Precision type lets you specify a fixed number 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 FloatingPointFormatStyle 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 floating-point values. The formatting that the modified style applies truncates precision to 0 after the fourth most-significant digit. let defaultStyle = FloatingPointFormatStyle<Double>(locale: Locale(identifier: "en_US")) let precisionStyle = defaultStyle.precision(.significantDigits(1...4)) let nums = [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"]

## See Also

### Customizing style behavior

- [decimalSeparator(strategy:)](foundation/floatingpointformatstyle/decimalseparator(strategy:).md)
- [grouping(_:)](foundation/floatingpointformatstyle/grouping(_:).md)
- [locale(_:)](foundation/floatingpointformatstyle/locale(_:).md)
- [notation(_:)](foundation/floatingpointformatstyle/notation(_:).md)
- [rounded(rule:increment:)](foundation/floatingpointformatstyle/rounded(rule:increment:).md)
- [scale(_:)](foundation/floatingpointformatstyle/scale(_:).md)
- [sign(strategy:)](foundation/floatingpointformatstyle/sign(strategy:).md)
- [FloatingPointFormatStyle.Configuration](foundation/floatingpointformatstyle/configuration.md)
- [NumberFormatStyleConfiguration](foundation/numberformatstyleconfiguration.md)
