将字符串转换为浮点数在Objective-C中 [英] Convert string to float in Objective-C
本文介绍了将字符串转换为浮点数在Objective-C中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Objective-C中将字符串转换为浮点数?
How do I convert a string to a float in Objective-C?
我正在尝试乘以从JSON返回的几个字符串:
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);
这给了我:(null)在控制台中.我知道该数组中有一个有效的字符串,因为我已经使用它在标签中显示其值了.
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.
推荐答案
your_float = [your_string floatValue];
尝试一下:
NSLog(@"float value is: %f", your_float);
这篇关于将字符串转换为浮点数在Objective-C中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文