示例#1
0
        private void Conv_button_Click(object sender, EventArgs e)
        {
            string temp1;
            string temp2 = "";

            from = int.Parse(fromBase.Text);
            to   = int.Parse(toBase.Text);
            string[] input = new string[2];
            input = textBox1.Text.Split(',');
            string intPart  = input[0];
            string realPart = input[1];

            BaseConverter.TryToBase(intPart, from, to, out temp1);
            RealConverter.TryToBase(realPart, from, to, out temp2, int.Parse(acc.Text));
            textBox1.Text = temp1 + "," + temp2;
        }
示例#2
0
        private void eq_Click(object sender, EventArgs e)
        {
            string[] t = new string[2];
            t[0] = "0";
            string[] n = new string[2];
            n = textBox1.Text.Split(sign);
            string temp1;
            string temp2;

            fromBase1 = int.Parse(tb_fromBase1.Text);
            fromBase2 = int.Parse(tb_fromBase2.Text);
            ansBase   = int.Parse(tb_ansBase.Text);
            if (!n[0].Contains(","))
            {
                n[0] += ",0";
            }
            if (!n[1].Contains(","))
            {
                n[1] += ",0";
            }



            string f_foreDot = n[0].Substring(0, n[0].IndexOf(',') - 1);
            string f_aftDot  = n[0].Substring(n[0].IndexOf(',') + 1);
            string s_foreDot = n[1].Substring(0, n[0].IndexOf(',') - 1);
            string s_aftDot  = n[1].Substring(n[0].IndexOf(',') + 1);

            BaseConverter.TryToBase(f_foreDot, fromBase1, 10, out temp1);
            RealConverter.TryToBase(f_aftDot, fromBase1, 10, out temp2, int.Parse(acc.Text));
            a = double.Parse(temp1 + ',' + temp2);
            BaseConverter.TryToBase(s_foreDot, fromBase1, 10, out temp1);
            RealConverter.TryToBase(s_aftDot, fromBase1, 10, out temp2, int.Parse(acc.Text));
            b = double.Parse(temp1 + ',' + temp2);

            try
            {
                switch (sign)
                {
                case '+':
                    result = a + b;
                    t      = result.ToString().Split(',');
                    if (result.ToString().Contains(","))
                    {
                        RealConverter.TryToBase(t[1], 10, ansBase, out temp2, int.Parse(acc.Text));
                    }
                    BaseConverter.TryToBase(t[0], 10, ansBase, out temp1);
                    textBox1.Text = result.ToString().Contains(",") ? temp1 + ',' + temp2 : temp1;
                    break;

                case '-':
                    result = a - b;
                    t      = result.ToString().Split(',');
                    if (result.ToString().Contains(","))
                    {
                        RealConverter.TryToBase(t[1], 10, ansBase, out temp2, int.Parse(acc.Text));
                    }
                    BaseConverter.TryToBase(t[0], 10, ansBase, out temp1);
                    textBox1.Text = result.ToString().Contains(",") ? temp1 + ',' + temp2 : temp1;
                    break;

                case '*':
                    result = a * b;
                    t      = result.ToString().Split(',');
                    if (result.ToString().Contains(","))
                    {
                        RealConverter.TryToBase(t[1], 10, ansBase, out temp2, int.Parse(acc.Text));
                    }
                    BaseConverter.TryToBase(t[0], 10, ansBase, out temp1);
                    textBox1.Text = result.ToString().Contains(",") ? temp1 + ',' + temp2 : temp1;
                    break;

                case '/':
                    result = a / b;
                    t      = result.ToString().Split(',');
                    if (result.ToString().Contains(","))
                    {
                        RealConverter.TryToBase(t[1], 10, ansBase, out temp2, int.Parse(acc.Text));
                    }
                    BaseConverter.TryToBase(t[0], 10, ansBase, out temp1);
                    textBox1.Text = result.ToString().Contains(",") ? temp1 + ',' + temp2 : temp1;
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }