public class FloatFormatter extends InternalFormat.Formatter
Constructor and Description |
---|
FloatFormatter(InternalFormat.Spec spec)
Construct the formatter from a specification, allocating a buffer internally for the result.
|
FloatFormatter(java.lang.StringBuilder result,
InternalFormat.Spec spec)
Construct the formatter from a client-supplied buffer, to which the result will be appended,
and a specification.
|
Modifier and Type | Method and Description |
---|---|
FloatFormatter |
append(char c) |
FloatFormatter |
append(java.lang.CharSequence csq) |
FloatFormatter |
append(java.lang.CharSequence csq,
int start,
int end) |
FloatFormatter |
format(double value)
Format a floating-point number according to the specification represented by this
FloatFormatter . |
FloatFormatter |
format(double value,
java.lang.String positivePrefix)
Format a floating-point number according to the specification represented by this
FloatFormatter . |
protected void |
reset()
Clear the instance variables describing the latest object in
InternalFormat.Formatter.result , ready to
receive a new one. |
protected int[] |
sectionLengths()
Supports
InternalFormat.Formatter.toString() by returning the lengths of the successive sections in the
result buffer, used for navigation relative to InternalFormat.Formatter.start . |
void |
setMinFracDigits(int minFracDigits)
Override the default truncation behaviour for the specification originally supplied.
|
static int |
size(InternalFormat.Spec spec)
Recommend a buffer size for a given specification, assuming one float is converted.
|
protected void |
uppercase()
Convert just the letters in the representation of the current number (in
InternalFormat.Formatter.result ) to
upper case. |
alignmentNotAllowed, alternateFormNotAllowed, alternateFormNotAllowed, getPyResult, getResult, groupDigits, isBytes, makeSpaceAt, notAllowed, notAllowed, pad, pad, precisionNotAllowed, precisionTooLarge, setBytes, setStart, signNotAllowed, toString, unknownFormat, zeroPadAfterSignWithGroupingFixup, zeroPaddingNotAllowed
public FloatFormatter(java.lang.StringBuilder result, InternalFormat.Spec spec)
InternalFormat.Formatter.mark
to the end of the buffer.result
- destination bufferspec
- parsed conversion specificationpublic FloatFormatter(InternalFormat.Spec spec)
spec
- parsed conversion specificationpublic static int size(InternalFormat.Spec spec)
spec
- parsed conversion specificationpublic void setMinFracDigits(int minFracDigits)
minFracDigits
, to modify this behaviour.minFracDigits
- 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.protected void reset()
InternalFormat.Formatter
InternalFormat.Formatter.result
, ready to
receive a new one. This is called from InternalFormat.Formatter.setStart()
. Subclasses override this
method and call InternalFormat.Formatter.setStart()
at the start of their format method.reset
in class InternalFormat.Formatter
protected int[] sectionLengths()
InternalFormat.Formatter
InternalFormat.Formatter.toString()
by returning the lengths of the successive sections in the
result buffer, used for navigation relative to InternalFormat.Formatter.start
. The toString
method shows a '|' character between each section when it prints out the buffer. Override
this when you define more lengths in the subclass.sectionLengths
in class InternalFormat.Formatter
public FloatFormatter append(char c)
append
in interface java.lang.Appendable
append
in class InternalFormat.Formatter
public FloatFormatter append(java.lang.CharSequence csq)
append
in interface java.lang.Appendable
append
in class InternalFormat.Formatter
public FloatFormatter append(java.lang.CharSequence csq, int start, int end) throws java.lang.IndexOutOfBoundsException
append
in interface java.lang.Appendable
append
in class InternalFormat.Formatter
java.lang.IndexOutOfBoundsException
public FloatFormatter format(double value)
FloatFormatter
.value
- to convertpublic FloatFormatter format(double value, java.lang.String positivePrefix)
FloatFormatter
. The conversion type, precision, and flags for grouping or
percentage are dealt with here. At the point this is used, we know the InternalFormat.Formatter.spec
is one
of the floating-point types. This entry point allows explicit control of the prefix of
positive numbers, overriding defaults for the format type.value
- to convertpositivePrefix
- to use before positive values (e.g. "+") or null to default to ""protected void uppercase()
InternalFormat.Formatter.result
) to
upper case. (That's the exponent marker or the "inf" or "nan".)uppercase
in class InternalFormat.Formatter