public class FloatFormatter
extends java.lang.Object
Various static methods helpful for formatting floating point values.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
stringValueForNaN |
static java.lang.String |
stringValueForNegativeInfinity |
static java.lang.String |
stringValueForPositiveInfinity |
Modifier and Type | Method and Description |
---|---|
static double[] |
fromString(java.lang.String s,
char delimChar)
Extract an arbitrary number of delimited numeric values from a string into an array of doubles.
|
static double[] |
fromString(java.lang.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(java.lang.String[] arg) |
static java.lang.String |
toString(double value)
Given a double value, return a string representation without too many decimal places.
|
static java.lang.String |
toString(double value,
java.util.Locale locale)
Given a double value, return a string representation without too many decimal places.
|
static java.lang.String |
toStringOfFixedMaximumLength(double value,
int maxLength,
boolean allowNonNumbers)
Given a double value, return a string representation that fits in a fixed length.
|
static java.lang.String |
toStringOfFixedMaximumLength(double value,
int maxLength,
boolean allowNonNumbers,
java.util.Locale locale)
Given a double value, return a string representation that fits in a fixed length.
|
public static java.lang.String stringValueForNaN
public static java.lang.String stringValueForNegativeInfinity
public static java.lang.String stringValueForPositiveInfinity
public static final double[] fromString(java.lang.String s, char delimChar)
Extract an arbitrary number of delimited numeric values from a string into an array of doubles.
s
- the string containing delimited double valuesdelimChar
- the delimiter characterpublic static final double[] fromString(java.lang.String s, int wanted, char delimChar)
Extract a specified number of delimited numeric values from a string into an array of doubles.
s
- the string containing delimited double valueswanted
- the number of double values wanteddelimChar
- the delimiter characterpublic static void main(java.lang.String[] arg)
public static java.lang.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.
value
- the value to format into a stringpublic static java.lang.String toString(double value, java.util.Locale locale)
Given a double value, return a string representation without too many decimal places.
value
- the value to format into a stringlocale
- locale to use when formatting (must be explicitly set to Locale.US when creating DICOM DS)public static java.lang.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.
value
- the value to format into a stringmaxLength
- the maximum length of the stringallowNonNumbers
- whether to return NaN and infinity as string values (true), or as zero length string (false)public static java.lang.String toStringOfFixedMaximumLength(double value, int maxLength, boolean allowNonNumbers, java.util.Locale locale)
Given a double value, return a string representation that fits in a fixed length.
value
- the value to format into a stringmaxLength
- the maximum length of the stringallowNonNumbers
- 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)