这是我的字符串,我想将变量浮点放在这个字符串中:
我想以 float 数据类型传递值。
比如..%.1f %.2f 我想在 iPhone sdk 中动态传递 1 和 2 值,我使用此代码:-----
NSString *string=[NSString stringWithFormat:@"%.%if",[[arrayvalue objectAtIndex:0] intValue],[textField2.text floatValue]];
但它只打印:-- .if
最佳答案
你不能嵌套格式字符串,你可以这样做:
int value = [[arrayvalue objectAtIndex:0] intValue];
NSString *string = [@"%." stringByAppendingFormat:@"%if", value];
string = [NSString stringWithFormat:string, [textField2.text floatValue]];
此代码完全未经测试。
关于iphone - 如何在 iPhone sdk 中传递 float 数据类型的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11795534/