0

Possible Duplicate:
NSString stringWithFormat adding a percent

a noob question here.

I have a code:

 int value = [sender value];
 [overLabel setText:[NSString stringWithFormat:@"Overhead: %d", (int)value]];

and this sets the label as (for example):

Overhead: 10

I'd like to be able to set it as:

Overhead: 10%

How do I implement the % into the string so it's not being used to print a value, but it's printed as an actual % character.

thank you!

Community
  • 1
  • 1
EarlGrey
  • 2,514
  • 4
  • 34
  • 63

2 Answers2

4

Just put two %, like this:

 [overLabel setText:[NSString stringWithFormat:@"Overhead: %d %%", (int)value]];
  • The [String Programming Guide](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265) has all the different format specifiers – Paul.s Nov 22 '11 at 22:58
2

You escape the % using two %.

int value = [sender value];
[overLabel setText:[NSString stringWithFormat:@"Overhead: %d%%", (int)value]];
Joe
  • 56,979
  • 9
  • 128
  • 135