Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在Obj C中的变量调用后直接添加%符号?_Objective C_Iphone - Fatal编程技术网

Objective c 如何在Obj C中的变量调用后直接添加%符号?

Objective c 如何在Obj C中的变量调用后直接添加%符号?,objective-c,iphone,Objective C,Iphone,我有一个计算用户输入的程序,我想用百分比表示。我只需要知道如何在代码中添加“%”符号,而不会使它崩溃 使用 lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f", ultimate_risk]; 打印出一个数字,比如18.4。我希望它打印出18.4%。我试过以下方法 lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f%", ultima

我有一个计算用户输入的程序,我想用百分比表示。我只需要知道如何在代码中添加“%”符号,而不会使它崩溃

使用

lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f", ultimate_risk];
打印出一个数字,比如18.4。我希望它打印出18.4%。我试过以下方法

lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f%", ultimate_risk];
而且它不会打印“%”符号。我试过以下方法

lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f\%\", ultimate_risk];
没有运气

这里缺少什么?

使用“%%”打印单个“%”。就是

lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f%%", ultimate_risk];
使用“%%”打印单个“%”。就是

lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f%%", ultimate_risk];

在Xcode中搜索文档以查找“字符串格式说明符”。您将在那里找到它们的完整列表。

在Xcode中搜索文档以查找“字符串格式说明符”。你会在那里找到他们的完整列表