When entering numbers into a string, display it as a calculator output. The type of output is excluded, 934,432. How else can you implement this task by eliminating the output using the built-in NSFormatter method and the like? Thank.
let newNumbers = makeNumber(number: "1234567894") print(newNumbers) } func makeNumber(number: String) -> String { let reversed = String(number.reversed()) var newText = "" for (index, character) in reversed.enumerated() { if index != 0 && index % 3 == 0 { newText.append(",") } newText.append(String(character)) } return String(newText.reversed()) When entering the digits number: "1234567894" at the output we get 1,234,567,894 . Excluded at the output ,234,567,894 if entered 234567894 . Insert commas from back to before separating by 3 characters, as it is displayed in the calculator.