significantDigits(_:)
Returns a precision that constrains formatted values to a range of significant digits.
Declaration
static func significantDigits<R>(_ limits: R) -> NumberFormatStyleConfiguration.Precision where R : RangeExpression, R.Bound == IntParameters
- limits:
A range from the minimum to the maximum number of significant digits to use when formatting values.
Return Value
A precision that constrains formatted values to a range of significant digits.
Discussion
When using this precision, the formatter rounds values that have more sigificant digits than the maximum of the range, as seen in the following example:
let myNum = 123456.formatted(.number
.precision(.significantDigits(2...4))
.rounded(rule: .down)) // "123,400"