我正在使用 KeyboardType = UIKeyboardTypeDecimalPad
,在某些手机上,您会在左下方看到一个“,”而不是“.”。这取决于手机的语言设置!与“。”当我使用 [NSNumber numberWithFloat:[textField.text floatValue]] 时,版本一切正常,但对于“,”版本,它表示 2.0 表示 2,5。有人知道解决方法吗?
最佳答案
您需要进行本地感知字符串转换,根据默认语言环境正确处理“2.5”和“2,5”。尝试:
NSNumber *num=[NSDecimalNumber decimalNumberWithString:textField.text];
来自 NSDecimalNumber Class Reference :
Whether the NSDecimalSeparator is a period (as is used, for example, in the United States) or a comma (as is used, for example, in France) depends on the default locale.
关于iphone - 将 NSString 转换为特定于语言环境的 NSNumber,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4602850/