问题
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