How to work with Fractions in java / How to do mathematical operations with Fractions in java

A fraction is a quantity which is not a whole number rather it is formed by using two numbers. A fraction has two parts : numerator and denominator separated by a “/”. Examples of fraction are : 15/2, 35/6
A fraction should always be represented in reduced(or simplest) form where there are no common multiples of numerator and denominator. For Example, 56/12 is not in its reduced from since its numerator and denominator still have common multiples. It reduced form will be 14/3(dividing both numerator and denominator by 4). For reducing a fraction to its simplest form, Greatest Common Divisor(GCD) of its numerator and denominator is calculated. GCD is the largest number from the common multiples of numerator and denominator. Both the numerator and denominator are divided by GCD to get the reduced form of fraction. In above case GCD of 56 and 12 is 4, dividing numerator and denominator by 4 gives 14/3 which is the simplest form of fraction.

(more…)

Continue Reading
Close Menu