Reputation: 1425
How to convert NSString value @"3.45" into float. 3.45
float fCost = [[NSDecimalNumber decimalNumberWithString:@"3.45"]floatValue] ;
Upvotes: 29
Views: 31430
Reputation: 53082
Reading your comment to Marek's answer it looks like your string actually = @"$3.45"
To convert that to a float use:
NSNumberFormatter * formatter = [[[NSNumberFormatter alloc] init] autorelease];
formatter.numberStyle = NSNumberFormatterCurrencyStyle;
formatter.currencyCode = @"USD";
float value = [[formatter numberFromString: @"$3.45"] floatValue];
Upvotes: 4
Reputation: 549
NSString's: - (float)floatValue;
For example:
NSString *str = @"3.45";
float f = [str floatValue];
Upvotes: 4