HandyJSON icon indicating copy to clipboard operation
HandyJSON copied to clipboard

NSNumber转String时NumberFormatter的使用问题

Open WZBbiao opened this issue 6 years ago • 0 comments

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?

WZBbiao avatar Jan 10 '20 07:01 WZBbiao