开发者

NSArry of floats issue

开发者 https://www.devze.com 2023-01-21 20:57 出处:网络
Im trying to create an NSArray of floats. However, once the value is added to the arrays it is alway 0.0000000.

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?


in the second NSLog, you are printing an NSNumber, not the float inside..to see that value..

NSLog(@"timeArray: %f", [[timeArray objectAtIndex:i] floatValue]);


try

NSLog(@"timeArray: %f", [[timeArray objectAtIndex:i] floatValue]);

at the end.

You're trying to print out the pointer to the NSNumber, not the value stored in it.

0

精彩评论

暂无评论...
验证码 换一张
取 消