【发布时间】:2022-08-18 17:10:14
【问题描述】:
-
由于某些原因?格式化程序使用设备的区域设置(语言)。如果您希望格式化程序使用特定的语言环境,您必须明确设置它。
标签: ios swift numberformatter
标签: ios swift numberformatter
你错了,格式化程序在模拟器和设备上都能正常工作——每个都使用不同的语言环境。如果这是向用户显示的数字,那么在用户的区域设置中格式化数字是完全正确的。
如果您想在任何地方使用特定的语言环境,您必须明确设置它,例如:
formatter.locale = Locale(identifier: "en_US")
【讨论】:
您需要指定formatter.locale,否则NumberFormatter 将从设备获取默认值。
https://developer.apple.com/documentation/foundation/numberformatter/1416967-locale
【讨论】: