Exemple #1
0
        /// <summary>
        /// Multiply two fractions
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>The product of a and b</returns>
        public static FractionModel Multiply(FractionModel a, FractionModel b)
        {
            var res = new FractionModel(a.Numerator * b.Numerator, a.Denominator * b.Denominator);

            res.Simplify();
            return(res);
        }
Exemple #2
0
        /// <summary>
        /// Subtracts two fractions
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>The difference of a and f=b</returns>
        public static FractionModel Subtract(FractionModel a, FractionModel b)
        {
            int           lcm = FindLeastCommonMultiple(a.Denominator, b.Denominator);
            int           num = a.Numerator * (lcm / a.Denominator) - b.Numerator * (lcm / b.Denominator);
            FractionModel res = new FractionModel(num, lcm);

            res.Simplify();

            return(res);
        }
        private void buttonSimplify_Click(object sender, System.EventArgs e)
        {
            FractionModel f = (FractionModel)listBoxFractions.SelectedItem;

            if (listBoxFractions.SelectedItem != null)
            {
                f.Simplify();
                fractions.ResetBindings();
            }
        }
Exemple #4
0
        /// <summary>
        /// Convert a decimal to a fraction
        /// </summary>
        /// <param name="d">The decimal to convert</param>
        /// <returns>The decimal represented as a fraction</returns>
        public static FractionModel ConvertDecimalToFraction(decimal d)
        {
            double decimalPlaces = NumberOfDecimalPlaces(d);
            int    multiplier    = (int)Math.Pow(10, decimalPlaces);

            FractionModel fraction = new FractionModel((int)(d * multiplier), multiplier);

            fraction.Simplify();

            return(fraction);
        }