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