0

我正在为 iPhone 安装一个 CalculatorApp,我只需要结束一件事,即浮点!

与普通计算器一样,我需要做一些事情,以便只允许一个“。” .

各位大佬能帮帮我吗?

4

2 回答 2

3

你有几种方法可以走,例如,NSStringrangeOfString方法,例如

#define FLOATING_POINT_STRING @"."; // set this to @"." or @"," according to the floating point type you want to use
float calculatorText = 45.194; // set this to whatever the label says, or you can skip the float => string conversion as shown below
NSString *text = [NSString stringWithFormat:@"%f", calculatorText];

if ([text rangeOfString:FLOATING_POINT_STRING].location != NSNotFound)
{
    // do nothing, there is a floating point
}
else
{ 
// append FLOATING_POINT_STRING to the label
}

祝你好运 ;)

于 2011-02-18T22:00:52.977 回答
1

您是否使用 UIButton 作为小数点按钮?如果是这样,您可以在按下它后立即禁用它。然后当然,在“清除”或“等于”或按下任何内容时重新启用它:

[buttonDecimalPoint setEnabled: NO];
于 2011-02-28T00:32:55.293 回答