Contents

grouping(_:)

Modifies the format style to use the specified grouping.

Declaration

func grouping(_ group: IntegerFormatStyle<Value>.Configuration.Grouping) -> IntegerFormatStyle<Value>

Parameters

  • group:

    The grouping to apply to the format style.

Return Value

An integer format style modified to use the specified grouping.

Discussion

The following example creates a default IntegerFormatStyle for the en_US locale, and a second style that never uses grouping. It then applies each style to an array of integers. The formatting that the modified style applies eliminates the three-digit grouping usually performed for the en_US locale.

let defaultStyle = IntegerFormatStyle<Int>(locale: Locale(identifier: "en_US"))
let neverStyle = defaultStyle.grouping(.never)
let nums = [100, 1000, 10000, 100000, 1000000]
let defaultNums = nums.map { defaultStyle.format($0) } // ["100", "1,000", "10,000", "100,000", "1,000,000"]
let neverNums = nums.map { neverStyle.format($0) } // ["100", "1000", "10000", "100000", "1000000"]

See Also

Customizing style behavior