问题
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