Formatting Numbers in Swift 3

Glatteisen picture Glatteisen · Jun 19, 2017 · Viewed 19.4k times · Source

I want to format number to this: 123.234.234.234 from 123234234234 depends on what the user types into the text field. I don't want to manage currency, it's not about currency, it is about the user has to type in a number and this number should be formatted correctly to be easier to read.

Not with a comma, with a dot.

I found only currency stuff in the whole research

Answer

Zell B. picture Zell B. · Jun 19, 2017

What you are looking for is probably groupingSeparator of NumberFormatter

let formater = NumberFormatter()
formater.groupingSeparator = "."
formater.numberStyle = .decimal
let formattedNumber = formater.string(from: number)