将字符串转换为Float

时间:2013-01-23 05:42:42

标签: iphone ios objective-c

我正在尝试将字符串解析为数组,在索引1处获取数组的一部分并将该字符串转换为float。我在这里有我的代码,但是我收到了错误“Intializing'flora',表达了不兼容的类型'NSString * _strong'。帮助!

NSString *csv = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv"]];

NSArray *array = [csv componentsSeparatedByString: @","];

NSString *price = [array objectAtIndex:1];

[price floatValue];

float currentPrice = price;

3 个答案:

答案 0 :(得分:3)

尝试

float currentPrice = [price floatValue];

答案 1 :(得分:0)

试试这个

float currentPrice = [price floatValue];

答案 2 :(得分:0)

your_float = [your_string floatValue];

试试这个:

NSLog(@"float value is: %f", your_float);