Example usage for org.apache.commons.lang.math Fraction getFraction

List of usage examples for org.apache.commons.lang.math Fraction getFraction

Introduction

In this page you can find the example usage for org.apache.commons.lang.math Fraction getFraction.

Prototype

public static Fraction getFraction(int whole, int numerator, int denominator) 

Source Link

Document

Creates a Fraction instance with the 3 parts of a fraction X Y/Z.

The negative sign must be passed in on the whole number part.

Usage

From source file:FractionExampleV1.java

public static void main(String args[]) {
    Fraction twoThirds = Fraction.TWO_THIRDS;
    Fraction fraction_whole = Fraction.getFraction(2, 2, 3);
    Fraction fraction = Fraction.getFraction(27, 98);
    Fraction fraction_double = Fraction.getFraction(4.56);
    Fraction fraction_string = Fraction.getFraction("2 1/3");

    System.err.println(twoThirds.doubleValue());
    System.err.println(fraction_string.getNumerator());
    System.err.println(fraction_whole.divideBy(fraction_double));
    System.err.println(fraction.divideBy(fraction));
}