I have string 99897.05 and I want to convert it like this 99 897.05 example: input: 8121.1 output 8 121.1
input 111111.11 output 111 111.11
I have string 99897.05 and I want to convert it like this 99 897.05 example: input: 8121.1 output 8 121.1
input 111111.11 output 111 111.11
What you need is the currencyGroupingSeparator:
let amount = 99897.05
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.currencyGroupingSeparator = " "
formatter.string(for: amount) //"$99 897.05"
You could change it whatever you'd like:
formatter.currencyGroupingSeparator = ""
formatter.string(for: amount) //"$99897.05"