Modifier and Type | Field and Description |
---|---|
private static final long | |
private int | lenExponent
The length of the exponent sign and digits or zero if there isn't one. |
private int | lenFraction
The length of the fractional part, right of the decimal point. |
private int | lenMarker
The length of the exponent marker ("e"), "inf" or "nan", or zero if there isn't one. |
private int | lenPoint
If it contains no decimal point, this length is zero, and 1 otherwise. |
pack-priv static final int | MAX_PRECISION
Limit the size of results. |
private int | minFracDigits
If |
pack-priv static final RoundingMode | ROUND_PY
The rounding mode dominant in the formatter. |
private static final long |
Access | Constructor and Description |
---|---|
public | FloatFormatter(StringBuilder
destination buffer result, InternalFormat.parsed conversion specification specConstruct the formatter from a client-supplied buffer, to which the result will be appended, and a specification. |
public | FloatFormatter(InternalFormat.
parsed conversion specification specConstruct the formatter from a specification, allocating a buffer internally for the result. |
Modifier and Type | Method and Description |
---|---|
public FloatFormatter | append(char
The character to append c)Overrides org. Implements java. Appendable .
|
public FloatFormatter | append(CharSequence
The character sequence to append. If csq)csq is
null , then the four characters "null" are
appended to this Appendable.Overrides org. Implements java. Appendable .
|
public FloatFormatter | append(CharSequence
The character sequence from which a subsequence will be
appended. If csq, int csq is null , then characters
will be appended as if csq contained the four
characters "null" .The index of the first character in the subsequence start, int The index of the character following the last character in the
subsequence end)Overrides org. Implements java. Appendable .
|
private void | appendExponent(int
exponent value to append exp)Append the current value of |
private void | appendExponential(CharSequence
from converting the value at a given precision. digits, int would be the exponent (in e-format), used to position
the decimal point. exp)Common code for g-format, none-format and r-format used when the exponent is such that an exponential presentation is chosen. |
private void | appendFixed(CharSequence
from converting the value at a given precision. digits, int would be the exponent (in e-format), used to position
the decimal point. exp, int of conversion (number of significant digits). precision)Common code for g-format, none-format and r-format used when the exponent is such that a fixed-point presentation is chosen. |
private void | appendPointAndTrailingZeros(int
smallest number of fractional digits on return n)Append the trailing fractional zeros, as required by certain formats, so that the total number of fractional digits is no less than specified. |
private void | appendTrailingZeros(int
smallest number of fractional digits on return n)Append the trailing fractional zeros, as required by certain formats, so that the total number of fractional digits is no less than specified. |
private void | ensurePointAndTrailingZeros(int
smallest number of fractional digits on return n)Append a decimal point and trailing fractional zeros if necessary for 'e' and 'f' format. |
public FloatFormatter | Returns: this objectto convert value)Format a floating-point number according to the specification
represented by this |
public FloatFormatter | |
private void | format_e(double
to convert value, String to use before positive values (e.g. "+") or
null to default to "" positivePrefix, int precision (maximum number of fractional digits) precision)The e-format helper function of |
private void | format_f(double
to convert value, String to use before positive values (e.g. "+") or
null to default to "" positivePrefix, int precision (maximum number of fractional digits) precision)The f-format inner helper function of
|
private void | format_g(double
to convert value, String to use before positive values (e.g. "+") or
null to default to "" positivePrefix, int total number of significant digits (precision 0
behaves as 1) precision, int +precision = the exponent at which
to resume using exponential notationImplementation of the variants of g-format, that uses Java's
|
private void | format_r(double
to convert value, String to use before positive values (e.g. "+") or
null to default to "" positivePrefix)Implementation of r-format ( |
private int | |
private void | removeTrailingZeros(int
smallest number of fractional digits on return n)Remove trailing zeros from the fractional part, as required by certain formats, leaving at least the number of fractional digits specified. |
private static int | Returns: the exponentto convert value, int maximum number of digits to return in
maxDigits, StringBuilder buf .for digits of result (recommend size be 20) buf)Convert a double to digits and an exponent for use in
|
protected void | reset()
Overrides org. result , ready to receive a new one.
|
protected int[] | sectionLengths()
Overrides org. toString() by returning the lengths of the
successive sections in the result buffer, used for navigation
relative to start .
|
public void | setMinFracDigits(int
if <0 prevent truncation; if ≥0 the
minimum number of fractional digits; when this is zero, and
all fractional digits are zero, the decimal point will also
be removed. minFracDigits)Override the default truncation behaviour for the specification originally supplied. |
private boolean | Returns: true if the value was one of "0", "-0", "nan, "inf", or "-inf".to convert value, String to use before positive values (e.g. "+") or
null to default to "" positivePrefix)Common code to deal with the sign, and the special cases "0", "-0", "nan, "inf", or "-inf". |
public static int | Returns: recommended a buffer sizeparsed conversion specification specRecommend a buffer size for a given specification, assuming one float is converted. |
protected void | uppercase()
Overrides org. result ) to upper case.
|
private void | zeroHelper(int
of conversion (number of significant digits). precision, int if zero, causes choice of exponential
notation for zero. expThreshold)Common code for g-format, none-format and r-format called when the conversion yields "inf", "nan" or zero. |
EXP_MASK | back to summary |
---|---|
private static final long EXP_MASK |
lenExponent | back to summary |
---|---|
private int lenExponent The length of the exponent sign and digits or zero if there isn't one. |
lenFraction | back to summary |
---|---|
private int lenFraction The length of the fractional part, right of the decimal point. |
lenMarker | back to summary |
---|---|
private int lenMarker The length of the exponent marker ("e"), "inf" or "nan", or zero if there isn't one. |
lenPoint | back to summary |
---|---|
private int lenPoint If it contains no decimal point, this length is zero, and 1 otherwise. |
MAX_PRECISION | back to summary |
---|---|
pack-priv static final int MAX_PRECISION Limit the size of results. No-one needs more than
|
minFracDigits | back to summary |
---|---|
private int minFracDigits If |
ROUND_PY | back to summary |
---|---|
pack-priv static final RoundingMode ROUND_PY The rounding mode dominant in the formatter. |
SIGN_MASK | back to summary |
---|---|
private static final long SIGN_MASK |
FloatFormatter | back to summary |
---|---|
public FloatFormatter(StringBuilder result, InternalFormat. Construct the formatter from a client-supplied buffer, to which
the result will be appended, and a specification. Sets
|
FloatFormatter | back to summary |
---|---|
public FloatFormatter(InternalFormat. Construct the formatter from a specification, allocating a buffer internally for the result.
|
append | back to summary |
---|---|
public FloatFormatter append(char c) Overrides org. Implements java. Doc from java. Appends the specified character to this
|
append | back to summary |
---|---|
public FloatFormatter append(CharSequence csq) Overrides org. Implements java. Doc from java. Appends the specified character sequence to this Depending on which class implements the character sequence
|
append | back to summary |
---|---|
public FloatFormatter append(CharSequence csq, int start, int end) throws IndexOutOfBoundsException Overrides org. Implements java. Doc from java. Appends a subsequence of the specified character sequence to this
An invocation of this method of the form out.append(csq.subSequence(start, end))
|
appendExponent | back to summary |
---|---|
private void appendExponent(int exp) Append the current value of
|
appendExponential | back to summary |
---|---|
private void appendExponential(CharSequence digits, int exp) Common code for g-format, none-format and r-format used when the
exponent is such that an exponential presentation is chosen.
Normally the method removes trailing digits so as to shorten the
presentation without loss of significance. Although no minimum
number of fractional digits is enforced in the exponential
presentation, when
|
appendFixed | back to summary |
---|---|
private void appendFixed(CharSequence digits, int exp, int precision) Common code for g-format, none-format and r-format used when the
exponent is such that a fixed-point presentation is chosen.
Normally the method removes trailing digits so as to shorten the
presentation without loss of significance. This method respects
the minimum number of fractional digits (digits after the decimal
point), in member
|
appendPointAndTrailingZeros | back to summary |
---|---|
private void appendPointAndTrailingZeros(int n) Append the trailing fractional zeros, as required by certain formats, so that the total number of fractional digits is no less than specified. If there is no decimal point originally (and therefore no fractional part), the method will add a decimal point, even if it adds no zeros.
|
appendTrailingZeros | back to summary |
---|---|
private void appendTrailingZeros(int n) Append the trailing fractional zeros, as required by certain
formats, so that the total number of fractional digits is no less
than specified. If
|
ensurePointAndTrailingZeros | back to summary |
---|---|
private void ensurePointAndTrailingZeros(int n) Append a decimal point and trailing fractional zeros if necessary
for 'e' and 'f' format. This should not be called if the result
is not numeric ("inf" for example). This method deals with the
following complexities: on return there will be at least the
number of fractional digits specified in the argument
|
format | back to summary |
---|---|
public FloatFormatter format(double value) throws FormatOverflow, FormatError Format a floating-point number according to the specification
represented by this
|
format | back to summary |
---|---|
public FloatFormatter format(double value, String positivePrefix) throws FormatOverflow, FormatError Format a floating-point number according to the specification
represented by this
|
format_e | back to summary |
---|---|
private void format_e(double value, String positivePrefix, int precision) The e-format helper function of
|
format_f | back to summary |
---|---|
private void format_f(double value, String positivePrefix, int precision) The f-format inner helper function of
|
format_g | back to summary | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
private void format_g(double value, String positivePrefix, int precision, int expThresholdAdj) Implementation of the variants of g-format, that uses Java's
None-format is the basis of
According to the Python documentation for g-format, the precise
rules are as follows: suppose that the result formatted with
presentation type The Python documentation says none-format is the same as g-format, but the observed behaviour differs from this, in that f-format is only used if -4 <= exp < p-1 (i.e. one less), and at least one digit to the right of the decimal point is preserved in the f-format (but not the e-format). That behaviour is controlled through the following arguments, with these recommended values:
|
format_r | back to summary |
---|---|
private void format_r(double value, String positivePrefix) Implementation of r-format (
|
indexOfMarker | back to summary |
---|---|
private int indexOfMarker() Return the index in |
removeTrailingZeros | back to summary |
---|---|
private void removeTrailingZeros(int n) Remove trailing zeros from the fractional part, as required by certain formats, leaving at least the number of fractional digits specified. If the resultant number of fractional digits is zero, this method will also remove the trailing decimal point (if there is one).
|
reprDigits | back to summary |
---|---|
private static int reprDigits(double value, int maxDigits, StringBuilder buf) Convert a double to digits and an exponent for use in
|
reset | back to summary |
---|---|
protected void reset() Overrides org. Doc from org. Clear the instance variables describing the latest object in
|
sectionLengths | back to summary |
---|---|
protected int[] sectionLengths() Overrides org. Doc from org. Supports
|
setMinFracDigits | back to summary |
---|---|
public void setMinFracDigits(int minFracDigits) Override the default truncation behaviour for the specification
originally supplied. Some formats remove trailing zero digits,
trimming to zero or one. Set member
|
signAndSpecialNumber | back to summary |
---|---|
private boolean signAndSpecialNumber(double value, String positivePrefix) Common code to deal with the sign, and the special cases "0",
"-0", "nan, "inf", or "-inf". If the method returns
|
size | back to summary |
---|---|
public static int size(InternalFormat. Recommend a buffer size for a given specification, assuming one float is converted. This will be a "right" answer for e and g-format, and for f-format with values up to 9,999,999.
|
uppercase | back to summary |
---|---|
protected void uppercase() Overrides org. Convert just the letters in the representation of the current
number (in
|
zeroHelper | back to summary |
---|---|
private void zeroHelper(int precision, int expThreshold) Common code for g-format, none-format and r-format called when the conversion yields "inf", "nan" or zero. The method completes formatting of the zero, with the appropriate number of decimal places or (in particular circumstances) exponential; notation.
|