Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString stringWithFormat adding a percent [duplicate]

How can I add a percent to my stringWithFormat function? For example, I'd like to have the following:

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

This should cause the string to be:

40.23% 

But it is not the case. How can I achieve this?

like image 284
CodeGuy Avatar asked Jan 03 '11 15:01

CodeGuy


1 Answers

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

float someFloat = 40.233f; NSString *str = [NSString stringWithFormat:@"%.02f%%",someFloat]; 
like image 132
F'x Avatar answered Oct 08 '22 19:10

F'x