How to convert a string to float? [duplicate]
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?
CGFloat strFloat = (CGFloat)[str floatValue];
Just pass the message floatValue
to the NSString
object. NSString::floatValue
精彩评论