Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format integer to 2 places

Tags:

integer

iphone

I'm trying to format integer to 2 characters, i.e. 01, 02, 03 instead of 1, 2, 3, 4.

I've done a few google searches but could not find anything. Can @"%d" be changed to reflect 2 characters ?

timeArray = [[NSMutableArray alloc] init];
 for (int i = 0; i < 25; i++){
  NSString *timeValue = [NSString stringWithFormat:@"%d", i];
  [timeArray addObject:timeValue];
  NSLog(@"Time: %@", timeValue);
 }

Regards, Stephen

like image 684
Stephen Avatar asked Sep 21 '10 15:09

Stephen


1 Answers

Got it !!!!

@"%02d"

like image 113
Stephen Avatar answered Oct 09 '22 09:10

Stephen