0

私はiPhone用のCalculatorAppを作成していますが、終了する必要があるのは浮動小数点だけです。

通常の電卓と同じように、1つの「。」だけを許可するように何かをする必要があります。。

男は私を助けることができますか?

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 に答える