Java org.apache.commons.lang.math Fraction fields, constructors, methods, implement or subclass

Example usage for Java org.apache.commons.lang.math Fraction fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for org.apache.commons.lang.math Fraction.

The text is from its open source code.

Field

FractionTWO_THIRDS
Fraction representation of 2/3.

Method

FractiondivideBy(Fraction fraction)

Divide the value of this fraction by another.

doubledoubleValue()

Gets the fraction as a double.

booleanequals(Object obj)

Compares this fraction to another object to test if they are equal.

.
intgetDenominator()

Gets the denominator part of the fraction.

FractiongetFraction(int whole, int numerator, int denominator)

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.

FractiongetFraction(int numerator, int denominator)

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

Any negative signs are resolved to be on the numerator.

FractiongetFraction(double value)

Creates a Fraction instance from a double value.

This method uses the continued fraction algorithm, computing a maximum of 25 convergents and bounding the denominator by 10,000.

FractiongetFraction(String str)

Creates a Fraction from a String.

The formats accepted are:

  1. double String containing a dot
  2. 'X Y/Z'
  3. 'Y/Z'
  4. 'X' (a simple whole number)
and a .

intgetNumerator()

Gets the numerator part of the fraction.

This method may return a value greater than the denominator, an improper fraction, such as the seven in 7/4.

FractionmultiplyBy(Fraction fraction)

Multiplies the value of this fraction by another, returning the result in reduced form.

Fractionreduce()

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.