public class OptionalNumberFormat extends Format
NumberFormat capable of handling nulls and empty strings.Format.Field| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object other) |
String |
format(double number)
Formats a
double number. |
String |
format(long number)
Formats a
long number. |
StringBuffer |
format(Object source,
StringBuffer buffer,
FieldPosition position) |
static Locale[] |
getAvailableLocales()
Returns all locales supported by the
get*Instance() methods. |
Currency |
getCurrency()
Returns the currency used by this format when formatting currency values.
|
static OptionalNumberFormat |
getCurrencyInstance()
Returns a currency format for the current default locale.
|
static OptionalNumberFormat |
getCurrencyInstance(Locale locale)
Returns a currency format for the given locale.
|
static OptionalNumberFormat |
getInstance()
Returns a general-purpose number format for the current default locale.
|
static OptionalNumberFormat |
getInstance(Locale locale)
Returns a general-purpose number format for the given locale.
|
static OptionalNumberFormat |
getIntegerInstance()
Returns an integer number format for the current default locale.
|
static OptionalNumberFormat |
getIntegerInstance(Locale locale)
Returns an integer number format for the given locale.
|
int |
getMaximumFractionDigits()
Returns the maximum number of digits allowed in the fraction part of a number.
|
int |
getMaximumIntegerDigits()
Returns the maximum number of digits allowed in the integer part of a number.
|
int |
getMinimumFractionDigits()
Returns the minimum number of digits allowed in the fraction part of a number.
|
int |
getMinimumIntegerDigits()
Returns the minimum number of digits allowed in the integer part of a number.
|
static OptionalNumberFormat |
getNumberInstance()
Returns a general-purpose number format for the current default locale.
|
static OptionalNumberFormat |
getNumberInstance(Locale locale)
Returns a general-purpose number format for the given locale.
|
static OptionalNumberFormat |
getPercentInstance()
Returns a percentage format for the current default locale.
|
static OptionalNumberFormat |
getPercentInstance(Locale locale)
Returns a percentage format for the given locale.
|
RoundingMode |
getRoundingMode()
Returns the rounding mode used in this format.
|
int |
hashCode() |
boolean |
isGroupingUsed()
Checks whether grouping is used in this format.
|
boolean |
isParseIntegerOnly()
Checks whether numbers shall be parsed as integers only.
|
Object |
parseObject(String source) |
Object |
parseObject(String source,
ParsePosition position) |
void |
setCurrency(Currency currency)
Sets the currency used by this format when formatting currency values.
|
void |
setGroupingUsed(boolean value)
Sets whether grouping is used in this format.
|
void |
setMaximumFractionDigits(int value)
Sets the maximum number of digits allowed in the fraction part of a number.
|
void |
setMaximumIntegerDigits(int value)
Sets the maximum number of digits allowed in the integer part of a number.
|
void |
setMinimumFractionDigits(int value)
Sets the minimum number of digits allowed in the fraction part of a number.
|
void |
setMinimumIntegerDigits(int value)
Sets the minimum number of digits allowed in the integer part of a number.
|
void |
setParseIntegerOnly(boolean value)
Sets whether numbers shall be parsed as integers only.
|
void |
setRoundingMode(RoundingMode roundingMode)
Sets the rounding mode used in this format.
|
clone, format, formatToCharacterIteratorpublic String format(double number)
double number.public String format(long number)
long number.public StringBuffer format(Object source, StringBuffer buffer, FieldPosition position)
public static Locale[] getAvailableLocales()
get*Instance() methods.public Currency getCurrency()
public static OptionalNumberFormat getCurrencyInstance()
public static OptionalNumberFormat getCurrencyInstance(Locale locale)
IllegalArgumentException - if locale is nullpublic static OptionalNumberFormat getInstance()
public static OptionalNumberFormat getInstance(Locale locale)
IllegalArgumentException - if locale is nullpublic static OptionalNumberFormat getIntegerInstance()
public static OptionalNumberFormat getIntegerInstance(Locale locale)
IllegalArgumentException - if locale is nullpublic int getMaximumFractionDigits()
public int getMaximumIntegerDigits()
public int getMinimumFractionDigits()
public int getMinimumIntegerDigits()
public static OptionalNumberFormat getNumberInstance()
public static OptionalNumberFormat getNumberInstance(Locale locale)
IllegalArgumentException - if locale is nullpublic static OptionalNumberFormat getPercentInstance()
public static OptionalNumberFormat getPercentInstance(Locale locale)
IllegalArgumentException - if locale is nullpublic RoundingMode getRoundingMode()
public boolean isGroupingUsed()
public boolean isParseIntegerOnly()
public Object parseObject(String source) throws ParseException
parseObject in class FormatParseExceptionpublic Object parseObject(String source, ParsePosition position)
parseObject in class Formatpublic void setCurrency(Currency currency)
public void setGroupingUsed(boolean value)
public void setMaximumFractionDigits(int value)
public void setMaximumIntegerDigits(int value)
public void setMinimumFractionDigits(int value)
public void setMinimumIntegerDigits(int value)
public void setParseIntegerOnly(boolean value)
public void setRoundingMode(RoundingMode roundingMode)