Top Fields Constructors Methods
org.apache.poi.ss.format

public Class SimpleFraction

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int
denominator

The denominator.

private final int
numerator

The numerator.

Constructor Summary

AccessConstructor and Description
public
SimpleFraction(int
the numerator
numerator
,
int
maxDenominator The maximum allowed value for denominator
denominator
)

Create a fraction given a numerator and denominator.

Method Summary

Modifier and TypeMethod and Description
public static SimpleFraction

Returns:

a SimpleFraction with the given values set.
buildFractionExactDenominator
(double
double value of fraction
val
,
int
the exact denominator
exactDenom
)

Create a fraction given a double value and a denominator.

public static SimpleFraction
buildFractionMaxDenominator(double
the double value to convert to a fraction.
value
,
int
maximum denominator value allowed.
maxDenominator
)

Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits.

private static SimpleFraction
buildFractionMaxDenominator(double
the double value to convert to a fraction.
value
,
double
maximum error allowed. The resulting fraction is within epsilon of value, in absolute terms.
epsilon
,
int
maximum denominator value allowed.
maxDenominator
,
int
maximum number of convergents
maxIterations
)

Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits.

public int

Returns:

the denominator.
getDenominator
()

Access the denominator.

public int

Returns:

the numerator.
getNumerator
()

Access the numerator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

denominatorback to summary
private final int denominator

The denominator.

numeratorback to summary
private final int numerator

The numerator.

Constructor Detail

SimpleFractionback to summary
public SimpleFraction(int numerator, int denominator)

Create a fraction given a numerator and denominator.

Parameters
numerator:int

the numerator

denominator:int

maxDenominator The maximum allowed value for denominator

Method Detail

buildFractionExactDenominatorback to summary
public static SimpleFraction buildFractionExactDenominator(double val, int exactDenom)

Create a fraction given a double value and a denominator.

Parameters
val:double

double value of fraction

exactDenom:int

the exact denominator

Returns:SimpleFraction

a SimpleFraction with the given values set.

buildFractionMaxDenominatorback to summary
public static SimpleFraction buildFractionMaxDenominator(double value, int maxDenominator)

Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits.

Parameters
value:double

the double value to convert to a fraction.

maxDenominator:int

maximum denominator value allowed.

Exceptions
IllegalStateException:
if the continued fraction failed to converge.
IllegalArgumentException:
if value > Integer.MAX_VALUE
buildFractionMaxDenominatorback to summary
private static SimpleFraction buildFractionMaxDenominator(double value, double epsilon, int maxDenominator, int maxIterations)

Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits.

References:

Based on org.apache.commons.math.fraction.Fraction from Apache Commons-Math. YK: The only reason of having this class is to avoid dependency on the Commons-Math jar.
Parameters
value:double

the double value to convert to a fraction.

epsilon:double

maximum error allowed. The resulting fraction is within epsilon of value, in absolute terms.

maxDenominator:int

maximum denominator value allowed.

maxIterations:int

maximum number of convergents

Exceptions
IllegalStateException:
if the continued fraction failed to converge.
IllegalArgumentException:
if value > Integer.MAX_VALUE
getDenominatorback to summary
public int getDenominator()

Access the denominator.

Returns:int

the denominator.

getNumeratorback to summary
public int getNumerator()

Access the numerator.

Returns:int

the numerator.