NSString stringWithFormat添加百分比 [英] NSString stringWithFormat adding a percent
本文介绍了NSString stringWithFormat添加百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在stringWithFormat函数中添加百分比?例如,我想要以下内容:
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];
这应该导致字符串为:
40.23%
但事实并非如此。我怎样才能实现这个目标?
But it is not the case. How can I achieve this?
推荐答案
%
成为开始printf的角色样式格式,它只需要加倍:
%
being the character beginning printf-style formats, it simply needs to be doubled:
float someFloat = 40.233f;
NSString *str = [NSString stringWithFormat:@"%.02f%%",someFloat];
这篇关于NSString stringWithFormat添加百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文