我有字符串99897.05,我想像这样转换它99 897.05 例: 输入:8121.1 输出8 121.1
输入111111.11 输出111 111.11
答案 0 :(得分:2)
您需要的是currencyGroupingSeparator:
let amount = 99897.05
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.currencyGroupingSeparator = " "
formatter.string(for: amount) //"$99 897.05"
您可以根据需要进行更改:
formatter.currencyGroupingSeparator = ""
formatter.string(for: amount) //"$99897.05"