从 UIPicker 中提取 NSString 后 NSString 转换为 doubleValue
我有:
NSInteger dollarrow = [ValuesPicker selectedRowInComponent:kDollar];
NSString *dollar = [dollarlist objectAtIndex:dollarrow];
double converteddollar=0;
我想对此进行 for 循环并获取 double 中的值,我正在尝试这样做:
for(dollar=1;dollar<=99;dollar++)
{
converteddollar = converteddollar + 2;
}
现在美元包含 NSString 我如何转换为 double 才能成功执行操作,然后
NSString *message = [[NSString alloc] initWithFormat:@"%0.2f",converteddollar];
我收到警告,并且应用程序是崩溃..我该如何纠正它。 我正在学习 Objective C 请帮忙。 谢谢 。 抱歉,我不想 == 我只是想使用 =
I have :
NSInteger dollarrow = [ValuesPicker selectedRowInComponent:kDollar];
NSString *dollar = [dollarlist objectAtIndex:dollarrow];
double converteddollar=0;
I want to do a for loop on this and get the value in double , I am trying this :
for(dollar=1;dollar<=99;dollar++)
{
converteddollar = converteddollar + 2;
}
Now the dollar contains NSString how do I convert into double to do the operation successfully and then
NSString *message = [[NSString alloc] initWithFormat:@"%0.2f",converteddollar];
I am getting warnings and the app is crashing .. How can I correct it .
I am learning Objective C please help .
Thankyou .
Sorry I did not want == i just wanted to use =
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的 for 循环是错误的。你真的想要'=='吗?我猜你只想要“=”。你不能使用这样的东西吗? (我只是举一个例子来指出循环中的错误。您的要求可能有所不同。而且我还没有编译代码,现在没有mac。所以您可能会遇到一些小错误)
Your for loop is wrong. Are you really want '=='? I guess you want only '='. Can't you use something like this? (I'm just giving an example to point the mistakes in loop. Your requirement may be something different. And also I have not compiled the code, don't have mac with me right now. So you may get some minor mistake)
很多错误...
selectedRowInComponent:
方法是一个成员方法。不是静态的。您需要在实例上调用它。==
是比较运算符。您想要的当然是一个带有单个=
符号的赋值。您声明一个指向 NSString 对象的指针。但它尚未初始化。
您还应该在循环中使用临时双变量。
我不明白你的循环应该做什么。你能解释一下吗?
Lots of errors...
The
selectedRowInComponent:
method is a member method. Not a static one. You need to call it on an instance.==
is a comparison operator. What you want is certainly an assignment, with a single=
sign.You declare a pointer to a NSString object. But it's not initialized.
You should also use a temporary double variable for your loop.
I don't understand what your loop is supposed to do. Can you explain a little bit?
NSString *dollar = [dollarlist objectAtIndex:dollarrow];
double conversiondollar = [dollar doubleValue];
应该可以工作(不需要for
循环)NSString *dollar = [dollarlist objectAtIndex:dollarrow];
double converteddollar = [dollar doubleValue];
should work (no need for youfor
loop)