Ejemplo n.º 1
0
        //分数配置
        public static Fraction_Math FractionSet(double num1, double num2)
        {
            Fraction_Math Franction = new Fraction_Math();
            int           opnext    = l.Next(4, 5);
            Fraction_Math result    = null;

            Franction.Denominator = num1;
            Franction.Numerator   = num2;
            switch (opnext)
            {
            case 1:
                result = Franction.Add(num1, num2);
                break;

            case 2:
                result = Franction.Sub(num1, num2);
                break;

            case 3:
                result = Franction.Multiple(num1, num2);
                break;

            case 4:
                result = Franction.Divided(num1, num2);
                break;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static string Fraction(string d1, string d2, char c1)
        {
            Fraction_Math fraction_Math = new Fraction_Math();
            DataTable     dt = new DataTable();
            Fraction_Math D1 = Score(d1), D2 = Score(d2);
            string        s;

            switch (c1)
            {
            case '+':
                Fraction_Math st = fraction_Math.Add(D1, D2);
                s = st.Numerator + "/" + st.Denominator;
                break;

            case '-':
                st = fraction_Math.Sub(D1, D2);
                s  = st.Numerator + "/" + st.Denominator;
                break;

            case '×':
                st = fraction_Math.Multiple(D1, D2);
                s  = st.Numerator + "/" + st.Denominator;
                break;

            case '÷':
                st = fraction_Math.Divided(D1, D2);
                s  = st.Numerator + "/" + st.Denominator;
                break;

            default:
                s = null;
                break;
            }

            if (Regex.IsMatch(dt.Compute(s, null).ToString(), @"^[+-]?\d*[.]?$"))
            {
                return(dt.Compute(s, null).ToString());
            }
            return(s);
        }