com.pixelmed.utils
Class FloatFormatter

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

public class FloatFormatter
extends Object

Various static methods helpful for formatting floating point values.


Field Summary
static String stringValueForNaN
           
static String stringValueForNegativeInfinity
           
static String stringValueForPositiveInfinity
           
 
Method Summary
static double[] fromString(String s, char delimChar)
          Extract an arbitrary number of delimited numeric values from a string into an array of doubles.
static double[] fromString(String s, int wanted, char delimChar)
          Extract a specified number of delimited numeric values from a string into an array of doubles.
static void main(String[] arg)
           
static String toString(double value)
          Given a double value, return a string representation without too many decimal places.
static String toString(double value, Locale locale)
          Given a double value, return a string representation without too many decimal places.
static String toStringOfFixedMaximumLength(double value, int maxLength, boolean allowNonNumbers)
          Given a double value, return a string representation that fits in a fixed length.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stringValueForNaN

public static String stringValueForNaN

stringValueForNegativeInfinity

public static String stringValueForNegativeInfinity

stringValueForPositiveInfinity

public static String stringValueForPositiveInfinity
Method Detail

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)