Class FloatFormatter

java.lang.Object
com.pixelmed.utils.FloatFormatter

public class FloatFormatter extends Object

Various static methods helpful for formatting floating point values.

  • Field Details

    • stringValueForNaN

      public static String stringValueForNaN
    • stringValueForNegativeInfinity

      public static String stringValueForNegativeInfinity
    • stringValueForPositiveInfinity

      public static String stringValueForPositiveInfinity
  • Method Details

    • toString

      public static String toString(double value)

      Given a double value, return a string representation without too many decimal places.

      Uses the default Locale for formatting, e.g., if the default is Locale.FRENCH, decimal point will be ",".

      Do NOT use this method for formatting strings that always need to have a period for a decimal point (such as DICOM DS values) but rather toString(double,Locale) and explictly specify the Locale to be Locale.US.

      Parameters:
      value - the value to format into a string
      Returns:
      the formatted string
    • toString

      public static String toString(double value, Locale locale)

      Given a double value, return a string representation without too many decimal places.

      Parameters:
      value - the value to format into a string
      locale - locale to use when formatting (must be explicitly set to Locale.US when creating DICOM DS)
      Returns:
      the formatted string
    • toStringOfFixedMaximumLength

      public static String toStringOfFixedMaximumLength(double value, int maxLength, boolean allowNonNumbers)

      Given a double value, return a string representation that fits in a fixed length.

      Uses the default Locale for formatting, e.g., if the default is Locale.FRENCH, decimal point will be ",".

      Do NOT use this method for formatting strings that always need to have a period for a decimal point (such as DICOM DS values) but rather toStringOfFixedMaximumLength(double,int,boolean,Locale) and explictly specify the Locale to be Locale.US.

      Parameters:
      value - the value to format into a string
      maxLength - the maximum length of the string
      allowNonNumbers - whether to return NaN and infinity as string values (true), or as zero length string (false)
      Returns:
      the formatted string
    • toStringOfFixedMaximumLength

      public static String toStringOfFixedMaximumLength(double value, int maxLength, boolean allowNonNumbers, Locale locale)

      Given a double value, return a string representation that fits in a fixed length.

      Parameters:
      value - the value to format into a string
      maxLength - the maximum length of the string
      allowNonNumbers - whether to return NaN and infinity as string values (true), or as zero length string (false)
      locale - locale to use when formatting (must be explicitly set to Locale.US when creating DICOM DS)
      Returns:
      the formatted string
    • fromString

      public static final double[] fromString(String s, int wanted, char delimChar)

      Extract a specified number of delimited numeric values from a string into an array of doubles.

      Parameters:
      s - the string containing delimited double values
      wanted - the number of double values wanted
      delimChar - the delimiter character
      Returns:
      an array of doubles of the size wanted containing the values, else null
    • fromString

      public static final double[] fromString(String s, char delimChar)

      Extract an arbitrary number of delimited numeric values from a string into an array of doubles.

      Parameters:
      s - the string containing delimited double values
      delimChar - the delimiter character
      Returns:
      an array of doubles of the size wanted containing the values, else null
    • main

      public static void main(String[] arg)