私はiPhone用のCalculatorAppを作成していますが、終了する必要があるのは浮動小数点だけです。
通常の電卓と同じように、1つの「。」だけを許可するように何かをする必要があります。。
男は私を助けることができますか?
私はiPhone用のCalculatorAppを作成していますが、終了する必要があるのは浮動小数点だけです。
通常の電卓と同じように、1つの「。」だけを許可するように何かをする必要があります。。
男は私を助けることができますか?
NSString
のrangeOfString
方法など、いくつかの方法があります。
#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
}
幸運を ;)
小数点ボタンにUIButtonを使用していますか?その場合は、押すとすぐに無効にすることができます。そしてもちろん、「クリア」または「等しい」、または押されたものが何であれ、それを再度有効にします。
[buttonDecimalPoint setEnabled: NO];