2

How do we display percentage character in objective-c?

I am using this:

[NSString localizedStringWithFormat:@"%.2f %", percentageQs]

But for some reason, it doesn't recognize the %. thought i could escape it using this \ but i was so wrong.

Frank
  • 3,073
  • 5
  • 40
  • 67
  • possible duplicate of [How to escape the % sign in C's printf?](http://stackoverflow.com/questions/1860159/how-to-escape-the-sign-in-cs-printf) – devnull Jul 21 '14 at 12:18

3 Answers3

17

There was a similar question tagged C asked earlier today: How to escape the sign in C . Answer here is the same... use a double %%.

Community
  • 1
  • 1
Jarret Hardie
  • 95,172
  • 10
  • 132
  • 126
4

% is used as an escape character, e.g. %@, %i, etc.

So to use the % sign then you use two, i.e. %%

Michael Waterfall
  • 20,497
  • 27
  • 111
  • 168
0

The code for percent sign in NSString format is %%. This is also true for NSLog() and printf() formats.

Hardik Mamtora
  • 1,642
  • 17
  • 23