notation(_:)
Modifies the format style to use the specified notation.
Declaration
func notation(_ notation: FloatingPointFormatStyle<Value>.Configuration.Notation) -> FloatingPointFormatStyle<Value>Parameters
- notation:
The notation to apply to the format style.
Return Value
A floating-point format style modified to use the specified notation.
Discussion
The following example creates a default FloatingPointFormatStyle for the en_US locale, and a second style that uses scientific notation style. It then applies each style to an array of floating-point values.
let defaultStyle = FloatingPointFormatStyle<Double>(locale: Locale(identifier: "en_US"))
let scientificStyle = defaultStyle.notation(.scientific)
let nums = [100.1, 1000.2, 10000.3, 100000.4, 1000000.5]
let defaultNums = nums.map { defaultStyle.format($0) } // ["100.1", "1,000.2", "10,000.3", "100,000.4", "1,000,000.5"]
let scientificNums = nums.map { scientificStyle.format($0) } // ["1.001E2", "1.0002E3", "1.00003E4", "1.000004E5", "1E6"]