List of usage examples for org.apache.commons.lang.math Fraction reduce
public Fraction reduce()
Reduce the fraction to the smallest values for the numerator and denominator, returning the result.
For example, if this fraction represents 2/4, then the result will be 1/2.
From source file:MainClass.java
public static void main(String[] args) { Fraction numer1 = Fraction.getFraction(3, 4); Fraction numer2 = Fraction.getFraction(51, 3509); Fraction numerator = numer1.multiplyBy(numer2); Fraction denominator = Fraction.getFraction(41, 59); Fraction result = numerator.divideBy(denominator); System.out.println("Expression as Fraction: " + result.reduce().toString()); System.out.println("Expression as double: " + result.doubleValue()); Fraction test1 = Fraction.getFraction(1, 2); Fraction test2 = Fraction.getFraction(2, 4); System.out.println("1/2 equals 2/4: " + test1.equals(test2)); double value = Fraction.getFraction(10000, 100000).pow(6).doubleValue(); double reduced = Fraction.getFraction(10000, 100000).reduce().pow(6).doubleValue(); System.out.println("Fraction to pow 6 without reduction: " + value); System.out.println("Fraction to pow 6 with reduction: " + reduced); }