If using Xcode to make an iOS calculator, how would I add a decimal button?

前端 未结 2 633
Happy的楠姐
Happy的楠姐 2021-01-26 17:35

How to add a decimal button so I don\'t have to do whole numbers? If i wanted any decimal number like 1.2 or 100.4 or 3.0 or anything like that, how would I add it to the calcul

2条回答
  •  孤街浪徒
    2021-01-26 18:35

    - (IBAction)Decimal:(id)sender{
        NSString *currentText = Text.text;
        if ([currentText rangeOfString:@"." options:NSBackwardsSearch].length == 0) {
            Text.text = [Text.text stringByAppendingString:@"."];  
        }
    }
    

提交回复
热议问题