Format class that handles Excel style fractions, such as "# #/#" and "#/###"
As of this writing, this is still not 100% accurate, but it does a reasonable job of trying to mimic Excel's fraction calculations. It does not currently maintain Excel's spacing.
This class relies on a method lifted nearly verbatim from org.apache.math.fraction. If further uses for Commons Math are found, we will consider adding it as a dependency. For now, we have in-lined the one method to keep things simple.
| Modifier and Type | Field and Description |
|---|---|
| private static final Pattern | |
| private final int | |
| private static final Logger | |
| private static final int | |
| private final int | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public | FractionFormat(String wholePartFormatString, String
The format string for the denominator denomFormatString)Single parameter ctor |
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| private String | |
| public StringBuffer | format(Object
The object to format obj, StringBuffer where the text is to be appended toAppendTo, FieldPosition A pos)FieldPosition identifying a field
in the formatted textImplements abstract java. Formats an object and appends the resulting text to a given string buffer. |
| public Object | parseObject(String
the source, ParsePosition String to parseA pos)ParsePosition object with index and error
index information as described above.Implements abstract java. Parses text from the given string to produce an object. |
| DENOM_FORMAT_PATTERN | back to summary |
|---|---|
| private static final Pattern DENOM_FORMAT_PATTERN | |
| exactDenom | back to summary |
|---|---|
| private final int exactDenom | |
| LOGGER | back to summary |
|---|---|
| private static final Logger LOGGER | |
| MAX_DENOM_POW | back to summary |
|---|---|
| private static final int MAX_DENOM_POW | |
| maxDenom | back to summary |
|---|---|
| private final int maxDenom | |
| wholePartFormatString | back to summary |
|---|---|
| private final String wholePartFormatString | |
| FractionFormat | back to summary |
|---|---|
| public FractionFormat(String wholePartFormatString, String denomFormatString) Single parameter ctor
| |
| format | back to summary |
|---|---|
public String format(Number num)
| |
| format | back to summary |
|---|---|
private String format(final BigDecimal decimal)
| |
| format | back to summary |
|---|---|
| public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) Implements abstract java. Doc from java. Formats an object and appends the resulting text to a given string
buffer.
If the
| |
| parseObject | back to summary |
|---|---|
| public Object parseObject(String source, ParsePosition pos) Implements abstract java. Doc from java. Parses text from the given string to produce an object.
This method attempts to parse text starting at the index given by
| |