Type Method
significantDigits(_:)
iOS 15.0+
iPadOS 15.0+
Mac Catalyst 15.0+
macOS 12.0+
tvOS 15.0+
watchOS 8.0+
Returns a precision that constrains formatted values to a given number of significant digits.
static func significantDigits(_ digits: Int) -> NumberFormatStyleConfiguration.Precision
Parameters
digitsThe maximum number of significant digits to use when formatting values.
Return Value
A precision that constrains formatted values to a given number of significant digits.
Discussion
When using this precision, the formatter rounds values that have more significant digits than the maximum of the range, as seen in the following example:
let myNum = 123456.formatted(.number
.precision(.significantDigits(4))
.rounded(rule: .down)) // "123,400"