How to convert a string to float? [duplicate]

£可爱£侵袭症+ 提交于 2019-12-10 01:21:16

问题


Possible Duplicate:
Convert string to float in Objective-C

I'd like to convert a string to a float.

/* dict is an NSDictionary to load Preferences */ 
NSString *str = [dict objectForKey:@"key"];

This is where I got. Now I'd like to convert the string value (in this case @"32.0f") in a float, where it could be processed by my application. How can I do this?


回答1:


CGFloat strFloat = (CGFloat)[str floatValue];



回答2:


Just pass the message floatValue to the NSString object. NSString::floatValue



来源:https://stackoverflow.com/questions/6240601/how-to-convert-a-string-to-float

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!