gpt4 book ai didi

ios - 了解 Swift 中货币的 NumberFormatter

转载 作者:搜寻专家 更新时间:2023-11-01 05:52:12 25 4
gpt4 key购买 nike

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

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

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

使用上面的代码并在我的应用程序中将手机的 Region 设置为中国 我得到 25,00 CNY 但在其他两个第三方应用程序中输出是25.00 人民币

我做错了什么?

区域设置为中国:

My App
25,00 CNY

Other Apps
CN¥25.00

区域设置为法国:

My App
25,00€

Other Apps
€25,00

但是当区域设置为美国时,我在所有三 (3) 个应用程序中得到相同的符号。

区域设置为美国:

My App
$25.00

Other Apps
$25.00

当区域设置为中国时,我特别担心输出,因为除了符号不同之外,我还得到了不同的符号 CNYCN¥ .

任何建议,我做错了什么吗?

最佳答案

剧透其他应用做错了,你的输出是正确的!

关于ios - 了解 Swift 中货币的 NumberFormatter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46447386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com