1

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?

mskfisher
  • 3,291
  • 4
  • 35
  • 48
user346443
  • 4,672
  • 15
  • 57
  • 80

2 Answers2

4

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.

Sam Dufel
  • 17,560
  • 3
  • 48
  • 51
4

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

NSLog(@"timeArray: %f", [[timeArray objectAtIndex:i] floatValue]);
Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56