小编use*_*653的帖子

给定整数时如何不显示不必要的零,但在需要时仍然有浮动答案

我有一个我正在开发的应用程序,我的一个功能是在需要时给出float或double值的答案,当答案是整数时给出一个整数

所以例如如果答案是8.52,则答案变为8.52,但当答案为8时,答案是8而不是8.0000,我不希望它显示所有额外的0.

- (IBAction) equalsbutton {
NSString *val = display.text;
switch(operation) {

    case Plus :
        display.text= [NSString stringWithFormat:@"%qi",[val longLongValue]+[storage longLongValue]];

    case Plus2 :
        display.text= [NSString stringWithFormat:@"%f",[val doubleValue]+[storage doubleValue]];
Run Code Online (Sandbox Code Playgroud)

这段代码似乎不起作用

objective-c nsstring format-specifiers stringwithformat ios

7
推荐指数
1
解决办法
3164
查看次数