开发者

Displaying percentage using NSString

开发者 https://www.devze.com 2022-12-13 21:30 出处:网络
How do we display percentage character in objective-c? I am using this: [NSString localizedStringWithFormat:@\"%.2f %\", percentageQs]

How do we display percentage character in objective-c?

I am using this:

[NSString localizedStringWithFormat:@"%.2f %", percentageQs]

But for some reason, it doesn't recognize the %. thought i could esca开发者_如何学Cpe it using this \ but i was so wrong.


There was a similar question tagged C asked earlier today: How to escape the sign in C . Answer here is the same... use a double %%.


% is used as an escape character, e.g. %@, %i, etc.

So to use the % sign then you use two, i.e. %%


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

0

精彩评论

暂无评论...
验证码 换一张
取 消