-4

我正在尝试将字符串解析为数组,在索引 1 处获取数组的一部分并将该字符串转换为浮点数。我有我的代码,但我收到错误“使用不兼容类型'NSString *_strong'的表达式初始化'float'。帮助!

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;
4

3 回答 3

3

尝试

float currentPrice = [price floatValue];
于 2013-01-23T05:43:50.097 回答
0

尝试这个

float currentPrice = [price floatValue];
于 2013-01-23T05:45:54.223 回答
0
your_float = [your_string floatValue];

尝试这个:

NSLog(@"float value is: %f", your_float);
于 2013-01-23T06:12:35.950 回答