tags:

views:

3378

answers:

2

Hi, I want to have a percentage sign in my string after a digit. Something like this: 75%.

How can I have this done? I tried:

[NSString stringWithFormat:@"%d\%", someDigit];

But it didn't work for me.

Thank you in advance.

+25  A: 

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

mouviciel
+14  A: 

The escape code for a percent sign is "%%", so your code would look like this

[NSString stringWithFormat:@"%d%%", someDigit];

Also, all the other format specifiers can be found at http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

porkchop