Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to float in Objective-C

How do I convert a string to a float in Objective-C?

I am trying to multiply a couple of strings I am getting back from JSON:

float subTotal = [[[[purchaseOrderItemsJSON objectAtIndex:i] objectAtIndex:j] objectForKey:@"Price"] floatValue];  NSLog(@"%@", subTotal); 

This gives me: (null) in the console. I know that there is a valid string coming out of that array because I am already using it to display its value in a label.

like image 510
Slee Avatar asked Jul 07 '10 00:07

Slee


1 Answers

your_float = [your_string floatValue]; 

EDIT:

try this:

  NSLog(@"float value is: %f", your_float); 
like image 150
Ramadheer Singh Avatar answered Sep 17 '22 11:09

Ramadheer Singh