How can I include a percent symbol (%) in my NSString?
[NSString stringWithFormat:@"Downloading (%1.0%)", percentage]
The above code does not include the last percent in the string.
Carl is right about the escaping, but it alone won't work with the code you have given. You are missing a format specifier after the first percentage sign. Given percentage
is a double, try:
[NSString stringWithFormat:@"Downloading (%.1f %%)", percentage];
Note the %.1f
, for formatting a double with one decimal. This gives 45.5 %
. Use %.f
for no decimals.
Also see http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/strings/Articles/formatSpecifiers.html
Use %%
to escape the percent sign.
[NSString stringWithFormat:@"Downloading (%g%%)", percentage];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With