NSString stringWithFormat adding a percent [duplicate] NSString stringWithFormat adding a percent [duplicate] ios ios

NSString stringWithFormat adding a percent [duplicate]


% being the character beginning printf-style formats, it simply needs to be doubled:

float someFloat = 40.233f;NSString *str = [NSString stringWithFormat:@"%.02f%%",someFloat];


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

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

This is also true for NSLog() and printf() formats.

Cited from How to add percent sign to NSString.