2010-09-16 23 views

回答

16

卡尔说得对逃逸,但它本身并不能与你给的代码工作。您在第一个百分号后缺少格式说明符。鉴于percentage是双,尝试:

[NSString stringWithFormat:@"Downloading (%.1f %%)", percentage]; 

注意%.1f,用于格式化双一位小数。这给了45.5 %。没有小数使用%.f

另请参阅http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/strings/Articles/formatSpecifiers.html

+0

非常感谢 - 不能相信,我离开了格式说明。看看昨天的代码太久了。 – TomH 2010-09-17 11:30:43

12

使用%%逃脱百分号。

+0

谢谢!但是,%%不起作用,但%%%做了。去搞清楚。 – TomH 2010-09-16 22:26:32

+1

@TomH,那么你的代码仍然有问题 - 查看@Mads答案以获取更多详细信息。 – 2010-09-16 22:39:22

2
[NSString stringWithFormat:@"Downloading (%g%%)",  percentage];