NSArry 浮点数问题
我正在尝试创建一个 NSArray 浮点数。但是,一旦将该值添加到数组中,它始终为 0.0000000。
我做错了什么?
NSLog(@"百分比:%f",百分比);打印正确的值和
NSLog(@"timeArray: %f", [timeArray objectAtIndex:i]);始终为 0.00000。
NSMutableArray *timeArray = [[NSMutableArray alloc] initWithCapacity:count];
for (int i = 0; i < count; i++) {
int time = Counter->getTime(i);
float percent = (float)(time - startTime) / (float)endTime;
NSLog(@"percent: %f" , percent); // This prints correct value
[timeArray addObject:[NSNumber numberWithFloat: percent]];
NSLog(@"timeArray: %f", [timeArray objectAtIndex:i]); // This prints 0.00000
}
我在使用 iPhone,内存不足,这可能是造成这种情况的原因吗?
Im trying to create an NSArray of floats. However, once the value is added to the arrays it is alway 0.0000000.
What am i doing wrong?
NSLog(@"percent: %f" , percent); prints the correct value and
NSLog(@"timeArray: %f", [timeArray objectAtIndex:i]); is always 0.00000.
NSMutableArray *timeArray = [[NSMutableArray alloc] initWithCapacity:count];
for (int i = 0; i < count; i++) {
int time = Counter->getTime(i);
float percent = (float)(time - startTime) / (float)endTime;
NSLog(@"percent: %f" , percent); // This prints correct value
[timeArray addObject:[NSNumber numberWithFloat: percent]];
NSLog(@"timeArray: %f", [timeArray objectAtIndex:i]); // This prints 0.00000
}
Im on the iphone and running out of memory, could that be causing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第二个 NSLog 中,您正在打印 NSNumber,而不是内部的浮点数..以查看该值..
in the second NSLog, you are printing an NSNumber, not the float inside..to see that value..
尝试
最后
一下。您试图打印出指向 NSNumber 的指针,而不是存储在其中的值。
try
at the end.
You're trying to print out the pointer to the NSNumber, not the value stored in it.