<!--
{
  "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/NumberFormatStyleConfiguration/Precision/integerAndFractionLength(integer:fraction:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation30NumberFormatStyleConfigurationO9PrecisionV24integerAndFractionLength0G08fractionAESi_SitFZ"
  },
  "title" : "integerAndFractionLength(integer:fraction:)"
}
-->

# integerAndFractionLength(integer:fraction:)

Returns a precision that constrains formatted values a given number of allowed digits in the integer and fraction parts.

```
static func integerAndFractionLength(integer: Int, fraction: Int) -> NumberFormatStyleConfiguration.Precision
```

## Parameters

`integer`

The number of digits to use when formatting the integer part of a number.

`fraction`

The number of digits to use when formatting the fraction part of a number.

## Return Value

A precision that constrains formatted values a given number of digits in the integer and fraction parts.

## Discussion

When using this precision, the formatter pads values with fewer digits than the specified digits for the integer or fraction parts. Similarly, it rounds values that have more digits than specified. The following example shows this behavior, padding the integer part while rounding the fraction:

```swift
let myNum = 12345.6789.formatted(.number
    .precision(.integerAndFractionLength(integer: 6,
                                         fraction: 3))
    .rounded(rule: .down)) // "012,345.678"
```

---

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)