Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying percentage using NSString

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.

like image 542
Frank Avatar asked Mar 16 '26 12:03

Frank


2 Answers

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 %%.

like image 76
Jarret Hardie Avatar answered Mar 19 '26 04:03

Jarret Hardie


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

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

like image 37
Michael Waterfall Avatar answered Mar 19 '26 04:03

Michael Waterfall