NumberStringConverter (JavaFX 28)
Description: declaration: module: javafx.base, package: javafx.util.converter, class: NumberStringConverter

# Class NumberStringConverter

java.lang.Object
javafx.util.StringConverter<Number>
javafx.util.converter.NumberStringConverter

Direct Known Subclasses:
  `CurrencyStringConverter, PercentageStringConverter`

public class NumberStringConverter extends StringConverter<Number>
A `StringConverter` implementation for `Number` values. Instances of this class are immutable unless created with the `NumberStringConverter(NumberFormat)` constructor (with a non-`null` argument).

Since:
  JavaFX 2.1

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NumberStringConverter()`
  Creates a `NumberStringConverter` that uses a formatter/parser based on the user's `Locale`.
  `NumberStringConverter(String pattern)`
  Creates a `NumberStringConverter` that uses a formatter/parser based on the user's `Locale` and the given decimal format pattern.
  `NumberStringConverter(NumberFormat numberFormat)`
  Creates a `NumberStringConverter` that uses the given formatter/parser.
  `NumberStringConverter(Locale locale)`
  Creates a `NumberStringConverter` that uses a formatter/parser based on the given locale.
  `NumberStringConverter(Locale locale, String pattern)`
  Creates a `NumberStringConverter` that uses a formatter/parser based on the given `Locale` and decimal format pattern.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Number`
  `fromString(String value)`
  Converts a string to an object.
  `String`
  `toString(Number value)`
  Converts an object to a string form.

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### NumberStringConverter

    public NumberStringConverter()
    Creates a `NumberStringConverter` that uses a formatter/parser based on the user's `Locale`.

  - ### NumberStringConverter

    public NumberStringConverter(Locale locale)
    Creates a `NumberStringConverter` that uses a formatter/parser based on the given locale.
    Parameters:
      `locale` - the `Locale` that will be used by the formatter/parser. If `null`, the user's locale will be used.

  - ### NumberStringConverter

    public NumberStringConverter(String pattern)
    Creates a `NumberStringConverter` that uses a formatter/parser based on the user's `Locale` and the given decimal format pattern.
    Parameters:
      `pattern` - the pattern describing the number format. If `null`, a default formatter/parser will be used.
    See Also:
      - `DecimalFormat`

  - ### NumberStringConverter

    public NumberStringConverter(Locale locale, String pattern)
    Creates a `NumberStringConverter` that uses a formatter/parser based on the given `Locale` and decimal format pattern.
    Parameters:
      `locale` - the `Locale` that will be used by the formatter/parser. If `null`, the user's locale will be used.
      `pattern` - the pattern describing the number format. If `null`, a default formatter/parser will be used.
    See Also:
      - `DecimalFormat`

  - ### NumberStringConverter

    public NumberStringConverter(NumberFormat numberFormat)
    Creates a `NumberStringConverter` that uses the given formatter/parser.
    Parameters:
      `numberFormat` - the formatter/parser that will be used by the `toString()` and `fromString()` methods. If `null`, a default formatter/parser will be used.

- ## Method Details

  - ### fromString

    public Number fromString(String value)
    Converts a string to an object. The parsing mechanism is defined by the specific converter. `null` and empty string are converted to `null`.
    Parameters:
      `value` - the `String` to convert
    Returns:
      an object of type `T` created from the string passed in

  - ### toString

    public String toString(Number value)
    Converts an object to a string form. The format of the returned string is defined by the specific converter. `null` is converted to an empty string, otherwise the type's `toString` is used.
    Parameters:
      `value` - the object of type `T` to convert
    Returns:
      a string representation of the object passed in