decimalSeparator(strategy:)
Modifies the format style to use the specified decimal separator display strategy.
Declaration
func decimalSeparator(strategy: FloatingPointFormatStyle<Value>.Configuration.DecimalSeparatorDisplayStrategy) -> FloatingPointFormatStyle<Value>Parameters
- strategy:
The decimal separator display strategy to apply to the format style.
Return Value
A floating-point format style modified to use the specified decimal separator display strategy.
Discussion
The following example creates a default FloatingPointFormatStyle for the en_US locale, and a second style that uses the always strategy. It then applies each style to an array of floating-point values that don’t have a fractional part. The formatting that the modified style applies adds a trailing decimal separator in all cases.
let defaultStyle = FloatingPointFormatStyle<Double>(locale: Locale(identifier: "en_US"))
let alwaysStyle = defaultStyle.decimalSeparator(strategy: .always)
let nums = [100.0, 1000.0, 10000.0, 100000.0, 1000000.0]
let defaultNums = nums.map { defaultStyle.format($0) } // ["100", "1,000", "10,000", "100,000", "1,000,000"]
let alwaysNums = nums.map { alwaysStyle.format($0) } // ["100.", "1,000.", "10,000.", "100,000.", "1,000,000."]