How to convert an NSString into an NSNumber

后端 未结 18 2346
一整个雨季
一整个雨季 2020-11-22 16:56

How can I convert a NSString containing a number of any primitive data type (e.g. int, float, char, unsigned int

18条回答
  •  爱一瞬间的悲伤
    2020-11-22 17:29

    You can use -[NSString integerValue], -[NSString floatValue], etc. However, the correct (locale-sensitive, etc.) way to do this is to use -[NSNumberFormatter numberFromString:] which will give you an NSNumber converted from the appropriate locale and given the settings of the NSNumberFormatter (including whether it will allow floating point values).

提交回复
热议问题