如何将字符串转换为浮点数?

Mat*_*toe 12 floating-point cocoa-touch objective-c nsstring ios

可能重复:
在Objective-C中将字符串转换为float

我想将一个字符串转换为一个浮点数.

/* dict is an NSDictionary to load Preferences */ 
NSString *str = [dict objectForKey:@"key"];
Run Code Online (Sandbox Code Playgroud)

这是我得到的地方.现在我想@"32.0f"在float中转换字符串值(在本例中),它可以由我的应用程序处理.我怎样才能做到这一点?

Sid*_*Sid 56

CGFloat strFloat = (CGFloat)[str floatValue];
Run Code Online (Sandbox Code Playgroud)


Mah*_*esh 6

只需将消息传递floatValueNSString对象即可.的NSString ::的floatValue