Top Description Fields Constructors Methods
org.apache.commons.math3.fraction

public Class ProperFractionFormat

extends FractionFormat
Class Inheritance
Imports
java.text.FieldPosition, .NumberFormat, .ParsePosition, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.exception.NullArgumentException, org.apache.commons.math3.util.FastMath, .MathUtils

Formats a Fraction number in proper format. The number format for each of the whole number, numerator and, denominator can be configured.

Minus signs are only allowed in the whole number part - i.e., "-3 1/2" is legitimate and denotes -7/2, but "-3 -1/2" is invalid and will result in a ParseException.

Since
1.1

Field Summary

Modifier and TypeField and Description
private static final long
private NumberFormat
wholeFormat

The format used for the whole number.

Constructor Summary

AccessConstructor and Description
public
ProperFractionFormat()

Create a proper formatting instance with the default number format for the whole, numerator, and denominator.

public
ProperFractionFormat(NumberFormat
the custom format for the whole, numerator, and denominator.
format
)

Create a proper formatting instance with a custom number format for the whole, numerator, and denominator.

public
ProperFractionFormat(NumberFormat
the custom format for the whole.
wholeFormat
,
NumberFormat
the custom format for the numerator.
numeratorFormat
,
NumberFormat
the custom format for the denominator.
denominatorFormat
)

Create a proper formatting instance with a custom number format for each of the whole, numerator, and denominator.

Method Summary

Modifier and TypeMethod and Description
public StringBuffer

Returns:

the value passed in as toAppendTo.
format
(Fraction
the object to format.
fraction
,
StringBuffer
where the text is to be appended
toAppendTo
,
FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
pos
)

Overrides org.apache.commons.math3.fraction.FractionFormat.format.

Formats a Fraction object to produce a string.

public NumberFormat

Returns:

the whole format.
getWholeFormat
()

Access the whole format.

public Fraction

Returns:

the parsed Fraction object.
parse
(String
the string to parse
source
,
ParsePosition
input/ouput parsing parameter.
pos
)

Overrides org.apache.commons.math3.fraction.FractionFormat.parse.

Parses a string to produce a Fraction object.

public void
setWholeFormat(NumberFormat
The new whole format value.
format
)

Modify the whole format.

Inherited from org.apache.commons.math3.fraction.FractionFormat:
formatformatFractiongetAvailableLocalesgetDefaultNumberFormatgetImproperInstancegetImproperInstancegetProperInstancegetProperInstanceparse

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.math3.fraction.FractionFormat.serialVersionUID.

Serializable version identifier

wholeFormatback to summary
private NumberFormat wholeFormat

The format used for the whole number.

Constructor Detail

ProperFractionFormatback to summary
public ProperFractionFormat()

Create a proper formatting instance with the default number format for the whole, numerator, and denominator.

ProperFractionFormatback to summary
public ProperFractionFormat(NumberFormat format)

Create a proper formatting instance with a custom number format for the whole, numerator, and denominator.

Parameters
format:NumberFormat

the custom format for the whole, numerator, and denominator.

ProperFractionFormatback to summary
public ProperFractionFormat(NumberFormat wholeFormat, NumberFormat numeratorFormat, NumberFormat denominatorFormat)

Create a proper formatting instance with a custom number format for each of the whole, numerator, and denominator.

Parameters
wholeFormat:NumberFormat

the custom format for the whole.

numeratorFormat:NumberFormat

the custom format for the numerator.

denominatorFormat:NumberFormat

the custom format for the denominator.

Method Detail

formatback to summary
public StringBuffer format(Fraction fraction, StringBuffer toAppendTo, FieldPosition pos)

Overrides org.apache.commons.math3.fraction.FractionFormat.format.

Formats a Fraction object to produce a string. The fraction is output in proper format.

Parameters
fraction:Fraction

the object to format.

toAppendTo:StringBuffer

where the text is to be appended

pos:FieldPosition

On input: an alignment field, if desired. On output: the offsets of the alignment field

Returns:StringBuffer

the value passed in as toAppendTo.

Annotations
@Override
getWholeFormatback to summary
public NumberFormat getWholeFormat()

Access the whole format.

Returns:NumberFormat

the whole format.

parseback to summary
public Fraction parse(String source, ParsePosition pos)

Overrides org.apache.commons.math3.fraction.FractionFormat.parse.

Parses a string to produce a Fraction object. This method expects the string to be formatted as a proper fraction.

Minus signs are only allowed in the whole number part - i.e., "-3 1/2" is legitimate and denotes -7/2, but "-3 -1/2" is invalid and will result in a ParseException.

Parameters
source:String

the string to parse

pos:ParsePosition

input/ouput parsing parameter.

Returns:Fraction

the parsed Fraction object.

Annotations
@Override
setWholeFormatback to summary
public void setWholeFormat(NumberFormat format)

Modify the whole format.

Parameters
format:NumberFormat

The new whole format value.

Exceptions
NullArgumentException:
if format is null.