gpt4 book ai didi

objective-c - 在 NSString 中包含 '%'?

转载 作者:太空狗 更新时间:2023-10-30 03:25:02 24 4
gpt4 key购买 nike

如何在我的 NSString 中包含百分号 (%)?

[NSString stringWithFormat:@"Downloading (%1.0%)",  percentage]

上面的代码不包括字符串中的最后一个百分比。

最佳答案

Carl 对转义的看法是正确的,但它不能单独使用您提供的代码。您在第一个百分号后缺少格式说明符。给定 percentage 是 double,尝试:

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

请注意 %.1f,用于格式化带一位小数的 double 。这给出了 45.5 %。使用 %.f 表示没有小数。

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

关于objective-c - 在 NSString 中包含 '%'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3731252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com