AFAIK its impossible using just [NSString stringWithFormat:@”%d”] since there is no specifiers for explicit displaying the + displaying, at least i didn’t find it at Apple Developer String Format Specifiers
So it looks like I have to use NSNumberFormatter in my case. I found how to set the plus sign representation but can’t figure out how to achieve my goal. I tried
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setPositiveFormat:@"+0"];
NSString strNumber = [numberFormatter stringFromNumber:[NSNumber numberWithInt:intSomeNumber]];
but I’m afraid it would cut numbers GT 9 to 1 digit and I don’t want that. I just want to display any positive int with + and any negative with -. Is this the right way maybe:
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setPositiveFormat:@"+#"];
NSString strNumber = [numberFormatter stringFromNumber:[NSNumber numberWithInt:intSomeNumber]];
From the very page you linked:
Now from the IEEE printf specification:
Example:
Result: