How to add percent sign to NSString

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.


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


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 Conceptual Strings Articles


如果在某些情况下有帮助,可以使用unicode字符:

NSLog(@"Test percentage uFF05");
链接地址: http://www.djcxy.com/p/35128.html

上一篇: 如何将NSString值转换为NSData?

下一篇: 如何将百分号添加到NSString