iOS13:尝试使用 es_ES 语言环境格式化 4 位数字时,NumberFormatter 缺少 groupingSeparator [英] iOS13: NumberFormatter missing groupingSeparator when try to format 4 digits numbers with es_ES locale
问题描述
我已将我的项目更新到 iOS 13,但我意识到我用于格式化价格的价格格式化程序已停止正常工作.
I've updated my project to iOS 13 and I've realised that the price formatter I was using for formatting the prices has stopped working correctly.
groupingSeparator
是将千位分组的符号,4 位数字缺失:使用西班牙语言环境 es_ES
时从 1000 到 9999.
The groupingSeparator
, the symbol that groups the thousands, is missing for 4 digits numbers: from 1000 to 9999 when using a the Spanish locale es_ES
.
下面有一个简单的截图来验证它.NumberFormatter
似乎适用于 en_US
语言环境和高于 9999 的数字,但每当使用 es_ES
语言环境并尝试格式化 4 位数字时,groupingSeparator
(千位分隔符)丢失,所以我得到的不是 1.000,而是 1000.
Below there is a simple snipped to verify it.
NumberFormatter
seems to be working perfectly for en_US
locale and for numbers higher than 9999 but whenever use es_ES
locale and try to format a 4 digits number, the groupingSeparator
(thousands separator) is missing, so instead of getting 1.000, I'm getting 1000.
let enFormatter = NumberFormatter()
enFormatter.locale = Locale(identifier: "en_US")
enFormatter.numberStyle = .decimal
enFormatter.string(from: 1000)
enFormatter.string(from: 9999)
enFormatter.string(from: 10000)
enFormatter.string(from: 100000)
let esFormatter = NumberFormatter()
esFormatter.locale = Locale(identifier: "es_ES")
esFormatter.numberStyle = .decimal
esFormatter.string(from: 1000)
esFormatter.string(from: 9999)
esFormatter.string(from: 10000)
esFormatter.string(from: 100000)
只需将其粘贴到 Playground 中并检查输出.
Just paste it into a playground and check the outputs.
我错过了什么吗?
到目前为止,我已经向 Apple 报告了这个问题:FB7416623
https://feedbackassistant.apple.com/feedback/7416623(不确定链接是否有效)
So far I've reported the problem to Apple: FB7416623
https://feedbackassistant.apple.com/feedback/7416623 (not sure if the link works)
我会保持更新,但如果有人能提供更多信息,我将不胜感激.
I'll keep this updated, but I would appreciate if anybody has more information about it.
推荐答案
基于 这篇来自 RAE 的文章(Real Academia de la Lengua Española:皇家西班牙语学院)和 另一个来自 Fundéu (Fundación del Español Urgente: Urgent Spanish Foundation),现在的规则是不使用 4 位数字的分组分隔符,并使用空格作为其余情况的分组分隔符.例如:
Based on this article from the RAE (Real Academia de la Lengua Española: Royal Academy of the Spanish Language), and this other one from the Fundéu (Fundación del Español Urgente: Urgent Spanish Foundation), right now the rule is not to use the grouping separator for 4 digits number, and use a white space as a grouping separator for the rest of the cases. For example:
1000 -> 1000
15000 -> 15 000
然而,ISO 规则建议即使对于 4 位数字也要保持分组分隔符.
However ISO rules recommend to keep the grouping separator even for 4 digits numbers.
这篇关于iOS13:尝试使用 es_ES 语言环境格式化 4 位数字时,NumberFormatter 缺少 groupingSeparator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!