Objective c 如何在字符串中包含百分比?

Objective c 如何在字符串中包含百分比?,objective-c,nsstring,Objective C,Nsstring,可能重复: 这里有个问题 我有一个密码: int value = [sender value]; [overLabel setText:[NSString stringWithFormat:@"Overhead: %d", (int)value]]; 这将标签设置为(例如): 我希望能够将其设置为: Overhead: 10% 如何将%实现到字符串中,使其不用于打印值,而是作为实际的%字符打印 谢谢大家! 使用两个%来转义% int value = [sender value]; [o

可能重复:

这里有个问题

我有一个密码:

 int value = [sender value];
 [overLabel setText:[NSString stringWithFormat:@"Overhead: %d", (int)value]];
这将标签设置为(例如):

我希望能够将其设置为:

Overhead: 10%
如何将%实现到字符串中,使其不用于打印值,而是作为实际的%字符打印


谢谢大家!

使用两个
%
来转义
%

int value = [sender value];
[overLabel setText:[NSString stringWithFormat:@"Overhead: %d%%", (int)value]];

您可以使用两个
%
来转义
%

int value = [sender value];
[overLabel setText:[NSString stringWithFormat:@"Overhead: %d%%", (int)value]];

只需将2%放在下面:

 [overLabel setText:[NSString stringWithFormat:@"Overhead: %d %%", (int)value]];

只需将2%放在下面:

 [overLabel setText:[NSString stringWithFormat:@"Overhead: %d %%", (int)value]];
具有所有不同的格式说明符具有所有不同的格式说明符