0

I need some response like 100 % but unable to print % after the number, as it comes with warning incomplete Identifier. enter image description here

I have tried searching solutions, used \%, '%' but no help.

Cœur
  • 37,241
  • 25
  • 195
  • 267
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
  • See also: http://stackoverflow.com/questions/739682/how-to-add-percent-sign-to-nsstring – Gary Johnson Mar 04 '13 at 16:23
  • 1
    I have found that `%%`, while the "right" way to do this, does not always work in all circumstances, and so I just make `'%'` a parameter and format with %c. – Hot Licks Mar 04 '13 at 16:25
  • @HotLicks I'm curious - do you have an example where it doesn't work as expected? – rmaddy Mar 04 '13 at 18:05
  • @maddy - Not at hand. And I was dealing with a lot of "mixed mode" stuff, some `stringWithFormat`, some `printf`, NSLog and other debug macros, et al, so it got pretty hairy trying to keep the exceptions straight. – Hot Licks Mar 04 '13 at 19:25

2 Answers2

3

Escape the special % character using another % character:

@"%2.0f%%"
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
2

The format specifier for a literal % is %%.

Jonathan Grynspan
  • 43,286
  • 8
  • 74
  • 104