NSNumber转String时NumberFormatter的使用问题
- Dominant language
- Swift
- Stars
- 4.3k
- Forks
- 677
- PR merge metrics
- No merged PRs in 30d
Description
NumberFormatter中有个locale属性,如果App支持国际化,当App切换到其他语言的时候,转换结果可能不是我们想要的。
比如把设备切换到阿拉伯环境,print(formatter.string(from: NSNumber(value: 50962))),打印结果为٥٠٩٦٢
如果我们需要在页面中显示,这个结果是正常的。
但是如果需要把这个数字作为参数传给服务端,服务端就没办法识别了
代码模拟这种情况:
`
let formatter = NumberFormatter()
formatter.usesGroupingSeparator = false
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 16
formatter.locale = Locale(identifier: "ar_CN")
print(formatter.string(from: NSNumber(value: 50962)))
`
能不能提供一种方式支持让使用者自己决定locale?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the provided NSNumber-to-String example with NumberFormatter using the Arabic locale, then trace where HandyJSON formats numeric values during serialization. Define how callers can choose the locale and verify that localized display output remains possible while serialized values are accepted by the server.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api, internationalization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100