Exemplo n.º 1
0
        // 1/xボタン
        private void xDivOneBtn_Click(object sender, EventArgs e)
        {
            // エラーメッセージが表示の判定と今の表示が0.かどうか判定
            if (display != Common.CALC_FORMAT && MyDetection.IsErrorMsg(display) == false)
            {
                decimal work = decimal.Parse(display);
                work = 1 / work;

                // 小数点があるかどうか
                if (MyDetection.IsValueToDot(work) == true)
                {
                    // あれば桁下げしておく
                    display = CalcManager.DotAdjust(work.ToString());
                }

                else
                {
                    // なければ最下位桁に点を追加
                    display = work.ToString() + '.';
                }

                // 桁区切り
                display        = CalcManager.ThousandSeparator(isSeparat, display);
                resultTxt.Text = display;
            }
        }
Exemplo n.º 2
0
        // +/-ボタン
        private void addToSubBtn_Click(object sender, EventArgs e)
        {
            // エラーメッセージが表示されているかどうか
            if (MyDetection.IsErrorMsg(display) == false)
            {
                // 前回の入力が演算子かどうか
                if (MyDetection.IsOperator(beforInput) == false)
                {
                    decimal work = decimal.Parse(display);  // 表示文字列をワークに代入
                    work   *= -1;                           // 符号を逆にする
                    display = work.ToString();              // 文字列化して保存

                    // 値が小数かどうか
                    if (MyDetection.IsValueToDot(work) == false)
                    {
                        display += '.';  // 値が少数ではないなら一番右端に 点(.)を追加
                    }
                }
                else
                {   // もし演算子なら表示を0.に戻す
                    display = Common.CALC_FORMAT;
                    isDot   = false;
                }

                // 桁区切り
                display        = CalcManager.ThousandSeparator(isSeparat, display);
                resultTxt.Text = display;
            }
        }
Exemplo n.º 3
0
        // MemoryRecollボタン
        private void memoryRecallBtn_Click(object sender, EventArgs e)
        {
            // エラーメッセージが表示されているかどうか
            if (MyDetection.IsErrorMsg(display) == false)
            {
                display = memory.ToString();    // 今のメモリに表示されている数字を表示用文字列に保存

                // 少数かどうか
                if (MyDetection.IsValueToDot(memory) == false)
                {
                    display += '.';
                }

                resultTxt.Text = display;       // 表示
                beforInput     = Common.M;
            }
        }
Exemplo n.º 4
0
        // sqrtボタン
        private void sqrtBtn_Click(object sender, EventArgs e)
        {
            // エラーメッセージが表示されているか
            if (MyDetection.IsErrorMsg(display) == false)
            {
                // decimal型に変換
                decimal work = decimal.Parse(display);

                // 変換した値がマイナスだった場合はエラー
                if (MyDetection.IsNegativeValue(work) == true)
                {
                    display = Common.ERROR3;
                }

                else
                {
                    work = CalcManager.DecimalSqrt(work);   // 平方根に直す

                    // 小数点があるかどうかを調べる
                    if (MyDetection.IsValueToDot(decimal.Parse(work.ToString())))
                    {
                        display = CalcManager.DotAdjust(work.ToString());
                    }

                    else
                    {
                        // ない場合は右端に点(.)をつける
                        display = work.ToString() + '.';
                    }
                }

                // 桁区切り
                display        = CalcManager.ThousandSeparator(isSeparat, display);
                resultTxt.Text = display;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 演算処理
        /// </summary>
        private void Calculate(Char operat)
        {
            beforInput    = operat;     // 前回入力された内容に演算子を入力された代入
            beforOperator = operat;     // 前回入力された演算子に入力された演算子代入

            switch (operatorStorage)
            {
            // 加算処理
            case Common.ADD:
                total = total + calcBuff;
                break;

            // 減産処理
            case Common.SUB:
                total = total - calcBuff;
                break;

            // 乗算処理
            case Common.MULTIPLY:
                total = total * calcBuff;
                break;

            // 除算処理
            case Common.DIVIDE:
                if (calcBuff == 0)
                {
                    if (total == 0)
                    {
                        // 0÷0の計算
                        display = Common.ERROR1;
                        break;
                    }
                    else
                    {
                        // X÷0の計算
                        display = Common.ERROR2;
                        break;
                    }
                }
                total = total / calcBuff;       // エラーではない場合は普通に計算
                break;

            // 合計に代入するだけ
            default:
                total = calcBuff;
                break;
            }

            // エラーがdisplayに入っていないか
            if (MyDetection.IsErrorMsg(display) == false)
            {
                if (operat != Common.EQUAL)
                {
                    // =演算子は代入しない
                    operatorStorage = operat;
                }

                // 数値を文字列化し表示用文字列に代入
                display = total.ToString();

                // 少数かどうか判定し,少数ではない場合は結果に小数点を付与
                if (MyDetection.IsValueToDot(total) == false)
                {
                    display += '.';
                }

                // 小数点以下無駄な0を省く
                display = CalcManager.DotAdjust(display);

                isDot = false;  // 小数点フラグOFF
            }

            // 桁区切り
            display        = CalcManager.ThousandSeparator(isSeparat, display);
            resultTxt.Text = display;
        }