org.python.core.stringlib

## Class FloatFormatter

- java.lang.Object
- - org.python.core.stringlib.InternalFormat.Formatter
  - - org.python.core.stringlib.FloatFormatter

All Implemented Interfaces:
  java.lang.Appendable

    public class FloatFormatter
    extends InternalFormat.Formatter

A class that provides the implementation of floating-point formatting. In a limited way, it acts like a StringBuilder to which text and one or more numbers may be appended, formatted according to the format specifier supplied at construction. These are ephemeral objects that are not, on their own, thread safe.

### Constructor Summary

Constructors
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.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`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`.
`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.

### Methods inherited from class org.python.core.stringlib.InternalFormat.Formatter

`alignmentNotAllowed, alternateFormNotAllowed, alternateFormNotAllowed, getPyResult, getResult, isBytes, notAllowed, notAllowed, pad, precisionNotAllowed, precisionTooLarge, setBytes, setStart, signNotAllowed, toString, unknownFormat, zeroPaddingNotAllowed`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### FloatFormatter

    public 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. Sets `InternalFormat.Formatter.mark` to the end of the buffer.

Parameters:
  `result` - destination buffer
  `spec` - parsed conversion specification

#### FloatFormatter

    public FloatFormatter(InternalFormat.Spec spec)

Construct the formatter from a specification, allocating a buffer internally for the result.

Parameters:
  `spec` - parsed conversion specification

### Method Detail

#### size

    public static int size(InternalFormat.Spec spec)

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.

Parameters:
  `spec` - parsed conversion specification

#### setMinFracDigits

    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 `minFracDigits`, to modify this behaviour.

Parameters:
  `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.

#### append

    public FloatFormatter append(char c)

Specified by:
  `append` in interface `java.lang.Appendable`
Overrides:
  `append` in class `InternalFormat.Formatter`

#### append

    public FloatFormatter append(java.lang.CharSequence csq)

Specified by:
  `append` in interface `java.lang.Appendable`
Overrides:
  `append` in class `InternalFormat.Formatter`

#### append

    public FloatFormatter append(java.lang.CharSequence csq,
                                 int start,
                                 int end)
                          throws java.lang.IndexOutOfBoundsException

Specified by:
  `append` in interface `java.lang.Appendable`
Overrides:
  `append` in class `InternalFormat.Formatter`
Throws:
  `java.lang.IndexOutOfBoundsException`

#### format

    public FloatFormatter format(double value)

Format a floating-point number according to the specification represented by this `FloatFormatter`.

Parameters:
  `value` - to convert
Returns:
  this object

#### format

    public FloatFormatter format(double value,
                                 java.lang.String positivePrefix)

Format a floating-point number according to the specification represented by this `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.

Parameters:
  `value` - to convert
  `positivePrefix` - to use before positive values (e.g. "+") or null to default to ""
Returns:
  this object