Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert NSString value @"3.45" into float?

Tags:

objective-c

How to convert NSString value @"3.45" into float. 3.45

float fCost = [[NSDecimalNumber decimalNumberWithString:@"3.45"]floatValue] ;
like image 858
user891268 Avatar asked Sep 30 '11 12:09

user891268


3 Answers

NSString *val = @"3.45";
float fCost = [val floatValue];
like image 119
Marek Sebera Avatar answered Nov 12 '22 18:11

Marek Sebera


float number = [string floatValue];
like image 38
kiran Avatar answered Nov 12 '22 17:11

kiran


NSString's: - (float)floatValue;

For example:

NSString *str = @"3.45";
float f = [str floatValue];
like image 4
Vladislav Brylinskiy Avatar answered Nov 12 '22 18:11

Vladislav Brylinskiy