了解Swift中货币的NumberFormatter

fs_*_*gre 1 number-formatting ios swift

我有一个应用程序,我正在尝试格式化Double,NumberFormetter但我得到的输出与其他应用程序中的输出不匹配.

这是我正在使用的代码......

let price:Double = 25
let currencyFormatter = NumberFormatter()
currencyFormatter.usesGroupingSeparator = true
currencyFormatter.numberStyle = .currency
currencyFormatter.locale = NSLocale.current

let priceFormatter = currencyFormatter.string(for: price)

myLabel.text = priceFormatter
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,并且Region在我的应用程序中将手机设置为中国,我得到的25,00 CNY是另外两个第三方应用程序的输出CN¥25.00.

我究竟做错了什么?

地区设为中国:

我的应用程序
25,00 CNY

其他应用程序
¥25.00

地区设置为法国:

我的应用程序
25,00€

其他应用程序
€25,00

但是当该区域设置为United States我在所有三(3)个应用程序中得到相同的表示法.

地区设置为美国:

我的应用程序
$ 25.00

其他应用
$ 25.00

我有点担心尤其是当区域设置为中国的输出,因为除了符号是不同的我也得到了不同的符号CNYVS CN¥.

有什么建议,我做错了吗?

Dam*_*rot 5

Spoiler其他应用程序做错了,你的输出是正确的!