Class OrdinateFormat

java.lang.Object
org.locationtech.jts.io.OrdinateFormat

public class OrdinateFormat extends Object
Formats numeric values for ordinates in a consistent, accurate way.

The format has the following characteristics:

  • It is consistent in all locales (in particular, the decimal separator is always a period)
  • Scientific notation is never output, even for very large numbers. This means that it is possible that output can contain a large number of digits.
  • The maximum number of decimal places reflects the available precision
  • NaN values are represented as "NaN"
  • Inf values are represented as "Inf" or "-Inf"
Author:
mdavis
  • Field Details

    • REP_POS_INF

      public static final String REP_POS_INF
      The output representation of Double.POSITIVE_INFINITY
      See Also:
    • REP_NEG_INF

      public static final String REP_NEG_INF
      The output representation of Double.NEGATIVE_INFINITY
      See Also:
    • REP_NAN

      public static final String REP_NAN
      The output representation of Double.NaN
      See Also:
    • MAX_FRACTION_DIGITS

      public static final int MAX_FRACTION_DIGITS
      The maximum number of fraction digits to support output of reasonable ordinate values. The default is chosen to allow representing the smallest possible IEEE-754 double-precision value, although this is not expected to occur (and is not supported by other areas of the JTS code).
      See Also:
    • DEFAULT

      public static OrdinateFormat DEFAULT
      The default formatter using the maximum number of digits in the fraction portion of a number.
  • Constructor Details

    • OrdinateFormat

      public OrdinateFormat()
      Creates an OrdinateFormat using the default maximum number of fraction digits.
    • OrdinateFormat

      public OrdinateFormat(int maximumFractionDigits)
      Creates an OrdinateFormat using the given maximum number of fraction digits.
      Parameters:
      maximumFractionDigits - the maximum number of fraction digits to output
  • Method Details

    • create

      public static OrdinateFormat create(int maximumFractionDigits)
      Creates a new formatter with the given maximum number of digits in the fraction portion of a number.
      Parameters:
      maximumFractionDigits - the maximum number of fraction digits to output
      Returns:
      a formatter
    • format

      public String format(double ord)
      Returns a string representation of the given ordinate numeric value.
      Parameters:
      ord - the ordinate value
      Returns:
      the formatted number string