NumberFormatter分组未按预期工作

问题描述 投票:0回答:1

正在研究货币格式,在尝试格式化智利比索时发现了一个问题。

以下代码:

let priceFormatter = NumberFormatter()
priceFormatter.locale = Locale(identifier: "es_CL")
priceFormatter.numberStyle = .currency
priceFormatter.currencyCode = "CLP"

priceFormatter.string(from: 9990) // A
priceFormatter.string(from: 99900) // B

执行此操作,我得到A$ 9990B$ 99.990。我要实现的是$ 9.990 for A

好像格式化程序没有在第一种情况下添加千分组分隔符,我不确定为什么。我尝试将groupingSize设置为3,但没有成功。

((仅发生4位数字)

swift nsnumberformatter currency-formatting
1个回答
0
投票

[基于this article from the RAE(西班牙皇家艺术学院:皇家西班牙语学院)和this other one from the Fundéu(西班牙紧急基金会:西班牙紧急基金会),目前的规则是,不得将分组分隔符用于4位数字,其余情况使用空格作为分组分隔符。例如:

1000  -> 1000
15000 -> 15 000

但是ISO规则建议将分组分隔符保留为4位数字。

© www.soinside.com 2019 - 2024. All rights reserved.