Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 468
Matoe Avatar asked Jun 05 '11 02:06

Matoe


2 Answers

CGFloat strFloat = (CGFloat)[str floatValue];
like image 94
Sid Avatar answered Sep 19 '22 19:09

Sid


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

like image 22
Mahesh Avatar answered Sep 22 '22 19:09

Mahesh