Xcode 将双精度和字符串组合成单个值?
基本上我有这个代码:Xcode 将双精度和字符串组合成单个值?,xcode,string,double,int,concatenation,Xcode,String,Double,Int,Concatenation,基本上我有这个代码: l11 = [NSString stringWithFormat: @"Health: %@", chealth, @"Ammo: %@", cammo]; 其中,l11是一个NSString,我希望它等于“生命值”+双切赫数+“弹药:”+双卡莫 现在,它工作得很好,但是它说在double应该是空的地方,即使它们被声明了,我测试了这个。如何解决这个问题?试试这个,假设chealth和cammo是double类型: l11 = [NSString stringWithFo
l11 = [NSString stringWithFormat: @"Health: %@", chealth, @"Ammo: %@", cammo];
其中,l11是一个NSString,我希望它等于“生命值”+双切赫数+“弹药:”+双卡莫
现在,它工作得很好,但是它说在double应该是空的地方,即使它们被声明了,我测试了这个。如何解决这个问题?试试这个,假设chealth和cammo是double类型:
l11 = [NSString stringWithFormat: @"Health: %f Ammo: %f", chealth, cammo];
您正试图将双精度(
%f
)格式化为对象(%@
)。阅读。chealth和cammo是双精度的吗?