How is the decimal separator in a `Locale` determined?

南笙酒味 提交于 2020-12-04 08:51:56

问题


I have this sample code:

let locale = Locale(identifier: "en_US")
print("Language code: \(locale.languageCode ?? "nil")")
print("Region code: \(locale.regionCode ?? "nil")")
print("Decimal separator: \(locale.decimalSeparator ?? "nil")")

Using en_US in this example (English as language and USA as region) makes the Locale’s decimal separator a . because this is the decimal separator in the specified region "USA":

Language code: en
Region code: US
Decimal separator: .

Using Locale(identifier: "fr_FR") (French in France) for locale makes the decimal separator a , (because this is how the do it in the region of France:

Language code: fr
Region code: FR
Decimal separator: ,

Using French (fr) for the language and the USA (US) for the region in the locale still gives me a , as decimal separator (which seems wrong because the decimal separator should not be determined by the language):

Language code: fr
Region code: US
Decimal separator: ,

The remaining combination would be en_FR which seemingly inconsequentially gives the decimal separator ,:

Language code: en
Region code: FR
Decimal separator: ,

What is the decimal separator dependant on?

Apple’s documentation only says this:

For example, for “en_US”, returns “.”.

(https://developer.apple.com/documentation/foundation/locale/2292886-decimalseparator)

How can I get a locale that is french in language but has a . as decimal separator? decimalSeparator is read only…

来源:https://stackoverflow.com/questions/64824106/how-is-the-decimal-separator-in-a-locale-determined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!