예제 #1
0
        /// <summary>
        /// Multiplication
        /// </summary>
        /// <param name="First">First fraction</param>
        /// <param name="Second">Second fraction</param>
        /// <returns>The resulting fraction</returns>
        public static Fraction operator *(Fraction First, Fraction Second)
        {
            Fraction Result = new Fraction(First.Numerator * Second.Numerator, First.Denominator * Second.Denominator);

            Result.Reduce();
            return(Result);
        }
예제 #2
0
        /// <summary>
        /// Subtraction
        /// </summary>
        /// <param name="First">First fraction</param>
        /// <param name="Second">Second fraction</param>
        /// <returns>The subtracted fraction</returns>
        public static Fraction operator -(Fraction First, Fraction Second)
        {
            Fraction Value1 = new Fraction(First.Numerator * (int)Second.Denominator, First.Denominator * Second.Denominator);
            Fraction Value2 = new Fraction(Second.Numerator * (int)First.Denominator, Second.Denominator * First.Denominator);
            Fraction Result = new Fraction(Value1.Numerator - Value2.Numerator, Value1.Denominator);

            Result.Reduce();
            return(Result);
        }
예제 #3
0
        /// <summary>
        /// Returns the proper string value of this fraction, reducing fractions if it can be done.  Returns just the whole number if the numerator is 0.
        /// </summary>
        /// <returns>WholeNumber Numerator/Denominator</returns>
        public string ToReducedString()
        {
            Fraction x = Fraction.Reduce(this);
            int      n = x.Numerator;
            int      d = x.Denominator;

            if (n < d)
            {
                return(x.ToString());
            }

            int wholes = n / d;
            int parts  = n % d;

            if (parts.Equals(0))
            {
                return(wholes.ToString());
            }
            else
            {
                return(string.Format("{0} {1}/{2}", wholes, parts, d));
            }
        }
예제 #4
0
 /// <summary>
 /// Subtraction
 /// </summary>
 /// <param name="First">First fraction</param>
 /// <param name="Second">Second fraction</param>
 /// <returns>The subtracted fraction</returns>
 public static Fraction operator -(Fraction First, Fraction Second)
 {
     Fraction Value1 = new Fraction(First.Numerator * (int)Second.Denominator, First.Denominator * Second.Denominator);
     Fraction Value2 = new Fraction(Second.Numerator * (int)First.Denominator, Second.Denominator * First.Denominator);
     Fraction Result = new Fraction(Value1.Numerator - Value2.Numerator, Value1.Denominator);
     Result.Reduce();
     return Result;
 }
예제 #5
0
 /// <summary>
 /// Multiplication
 /// </summary>
 /// <param name="First">First fraction</param>
 /// <param name="Second">Second fraction</param>
 /// <returns>The resulting fraction</returns>
 public static Fraction operator *(Fraction First, Fraction Second)
 {
     Fraction Result = new Fraction(First.Numerator * Second.Numerator, First.Denominator * Second.Denominator);
     Result.Reduce();
     return Result;
 }