integerAndFractionLength(integer:fraction:)
Returns a precision that constrains formatted values a given number of allowed digits in the integer and fraction parts.
Declaration
static func integerAndFractionLength(integer: Int, fraction: Int) -> NumberFormatStyleConfiguration.PrecisionParameters
- 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:
let myNum = 12345.6789.formatted(.number
.precision(.integerAndFractionLength(integer: 6,
fraction: 3))
.rounded(rule: .down)) // "012,345.678"