public class DoubleConversion
extends java.lang.Object
java.text.NumberFormat
.To convert double to String, this class adds support for easily constructing a NumberFormat as well as setting fraction and integer precision parameters in a single method.
Constructor and Description |
---|
DoubleConversion() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
doubleToString(boolean value)
Converts the given Boolean to String.
|
static java.lang.String |
doubleToString(double value)
Converts a double to String using the default Locale and standard NumberFormat.
|
static java.lang.String |
doubleToString(double value,
int maxFractionDigits,
int minFractionDigits,
int maxIntegerDigits,
int minIntegerDigits)
Converts a double to String using current Locale and specified fraction
and integer lengths that are used in conjunction with a NumberFormat.
|
static java.lang.String |
doubleToString(double value,
int maxFractionDigits,
int minFractionDigits,
int maxIntegerDigits,
int minIntegerDigits,
java.util.Locale locale)
Converts a double to String using given Locale, fraction, and integer lengths
that are used in conjunction with a NumberFormat.
|
static java.lang.String |
doubleToString(long value)
Converts a long to String
|
static java.text.NumberFormat |
getFormat(int maxFractionDigits,
int minFractionDigits,
int maxIntegerDigits,
int minIntegerDigits,
java.util.Locale locale)
Constructs and returns a NumberFormat with given precision parameters and Locale.
|
static java.text.NumberFormat |
getScientificFormat(java.text.NumberFormat base,
java.util.Locale locale)
Constructs and returns a NumberFormat that can be used for formatting
decimal values into scientific notation.
|
static java.text.NumberFormat |
getStandardFormat(java.util.Locale locale)
Constructs a NumberFormat for given locale, using the following parameters:
maxFractionDigits = 20,
minFractionDigits = 1,
maxIntegerDigits = 20,
minIntegerDigits = 1.
|
static double |
stringToDouble(java.lang.String value)
Converts a String to a double using the standard NumberFormat with current
default Locale.
|
static double |
stringToDouble(java.lang.String value,
double defaultValue)
Converts a String to a double using the standard NumberFormat with current
default Locale.
|
static double |
stringToDouble(java.lang.String value,
double defaultValue,
java.util.Locale locale)
Converts a String to a double using the standard NumberFormat with given Locale.
|
static double |
stringToDouble(java.lang.String value,
double defaultValue,
java.text.NumberFormat format)
Converts a String to a double using the given NumberFormat.
|
static double |
stringToDouble(java.lang.String value,
java.util.Locale locale)
Converts a String to a double using the standard NumberFormat with specified locale.
|
static double |
stringToDouble(java.lang.String value,
java.text.NumberFormat format)
Converts a String to a double using the specified NumberFormat.
|
public static java.text.NumberFormat getFormat(int maxFractionDigits, int minFractionDigits, int maxIntegerDigits, int minIntegerDigits, java.util.Locale locale)
maxFractionDigits
- the maximum number of faction digitsminFractionDigits
- the minumum number of faction digitsmaxIntegerDigits
- the maximum number of integer digitsminIntegerDigits
- the minimum number of integer digitslocale
- the localepublic static java.text.NumberFormat getStandardFormat(java.util.Locale locale)
locale
- the localepublic static java.text.NumberFormat getScientificFormat(java.text.NumberFormat base, java.util.Locale locale)
The NumberFormat will have a pattern applied that is constructed
using the number of integer and fraction characters within the
given NumberFormat. It is expected that the base
format will be
used for regular number formatting, and the format constructed by this method will
be used for scientific notation when the base
format is
inappropriate (the number is to large or too small for the base format).
base
- the base number formatlocale
- the localepublic static java.lang.String doubleToString(double value, int maxFractionDigits, int minFractionDigits, int maxIntegerDigits, int minIntegerDigits, java.util.Locale locale)
value
- the double to convertmaxFractionDigits
- the maximum number of fraction digitsminFractionDigits
- the minimum number of fraction digitsmaxIntegerDigits
- the maximum number of integer digitsminIntegerDigits
- the minimum number of integer digitslocale
- the localeNumberFormat
public static java.lang.String doubleToString(double value, int maxFractionDigits, int minFractionDigits, int maxIntegerDigits, int minIntegerDigits)
value
- the double to convertmaxFractionDigits
- the maximum number of fraction digitsminFractionDigits
- the minimum number of fraction digitsmaxIntegerDigits
- the maximum number of integer digitsminIntegerDigits
- the minimum number of integer digitsNumberFormat
public static java.lang.String doubleToString(double value)
value
- the double to convertDoubleConversion.doubleToString(double,int,int,int,int)
,
DoubleConversion.getStandardFormat(java.util.Locale)
public static java.lang.String doubleToString(boolean value)
value
- the boolean to convertpublic static java.lang.String doubleToString(long value)
value
- the long to convertpublic static double stringToDouble(java.lang.String value, double defaultValue, java.text.NumberFormat format)
ParsingException
occurs.value
- the String value to be converteddefaultValue
- the default value to use in case of parsing errorformat
- the NumberFormat to be usedpublic static double stringToDouble(java.lang.String value, double defaultValue, java.util.Locale locale)
ParsingException
occurs.value
- the String value to be converteddefaultValue
- the default value to use in case of parsing errorlocale
- the Locale to be usedpublic static double stringToDouble(java.lang.String value)
ParsingException
occurs.value
- the String value to be convertedpublic static double stringToDouble(java.lang.String value, double defaultValue)
ParsingException
occurs.value
- the String value to be converteddefaultValue
- the default value to use in case of parsing errorpublic static double stringToDouble(java.lang.String value, java.util.Locale locale) throws java.text.ParseException
value
- the String value to be convertedlocale
- the Locale to be used when constructing standard formatjava.text.ParseException
- if parse errors occurpublic static double stringToDouble(java.lang.String value, java.text.NumberFormat format) throws java.text.ParseException
value
- the String value to be convertedformat
- the NumberFormat to be usedjava.text.ParseException
- if parse errors occur