integerAndFractionLength(integerLimits:fractionLimits:)
Returns a precision that constrains formatted values to ranges of allowed digits in the integer and fraction parts.
Declaration
static func integerAndFractionLength<R1, R2>(integerLimits: R1, fractionLimits: R2) -> NumberFormatStyleConfiguration.Precision where R1 : RangeExpression, R2 : RangeExpression, R1.Bound == Int, R2.Bound == IntParameters
- integerLimits:
A range from the minimum to the maximum number of digits to use when formatting the integer part of a number.
- fractionLimits:
A range from the minimum to the maximum number of digits to use when formatting the fraction part of a number.
Return Value
A precision that constrains formatted values to ranges of digits in the integer and fraction parts.
Discussion
When using this precision, the formatter rounds values that have more digits than the maximum of the range, as seen in the following example:
let myNum = 12345.6789.formatted(.number
.precision(.integerAndFractionLength(integerLimits: 2...,
fractionLimits: 2...3))
.rounded(rule: .down)) // "12,345.678"