|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.text.Format
java.text.NumberFormat
public abstract class NumberFormat
This is the abstract superclass of all classes which format and parse numeric values such as decimal numbers, integers, currency values, and percentages. These classes perform their parsing and formatting in a locale specific manner, accounting for such items as differing currency symbols and thousands separators.
To create an instance of a concrete subclass of NumberFormat,
do not call a class constructor directly. Instead, use one of the
static factory methods in this class such as
getCurrencyInstance.
| Nested Class Summary | |
|---|---|
static class |
NumberFormat.Field
|
| Field Summary | |
|---|---|
static int |
FRACTION_FIELD
This is a constant used to create a FieldPosition object
that will return the fractional portion of a formatted number. |
static int |
INTEGER_FIELD
This is a constant used to create a FieldPosition object
that will return the integer portion of a formatted number. |
| Constructor Summary | |
|---|---|
protected |
NumberFormat()
This is a default constructor for use by subclasses. |
| Method Summary | |
|---|---|
boolean |
equals(Object obj)
This method tests the specified object for equality against this object. |
String |
format(double number)
This method is a specialization of the format method that performs a simple formatting of the specified double number. |
abstract StringBuffer |
format(double number,
StringBuffer sbuf,
FieldPosition pos)
This method formats the specified double and appends it to
a StringBuffer. |
String |
format(long number)
This method is a specialization of the format method that performs a simple formatting of the specified long number. |
abstract StringBuffer |
format(long number,
StringBuffer sbuf,
FieldPosition pos)
This method formats the specified long and appends it to
a StringBuffer. |
StringBuffer |
format(Object obj,
StringBuffer sbuf,
FieldPosition pos)
This method formats an Object into a String and
appends the String to a StringBuffer. |
static Locale[] |
getAvailableLocales()
This method returns a list of locales for which concrete instances of NumberFormat subclasses may be created. |
Currency |
getCurrency()
Returns the currency used by this number format when formatting currency values. |
static NumberFormat |
getCurrencyInstance()
This method returns an instance of NumberFormat suitable
for formatting and parsing currency values in the default locale. |
static NumberFormat |
getCurrencyInstance(Locale loc)
This method returns an instance of NumberFormat suitable
for formatting and parsing currency values in the specified locale. |
static NumberFormat |
getInstance()
This method returns a default instance for the default locale. |
static NumberFormat |
getInstance(Locale loc)
This method returns a default instance for the specified locale. |
static NumberFormat |
getIntegerInstance()
This method returns an integer formatting and parsing class for the default locale. |
static NumberFormat |
getIntegerInstance(Locale locale)
This method returns an integer formatting and parsing class for the default locale. |
int |
getMaximumFractionDigits()
This method returns the maximum number of digits allowed in the fraction portion of a number. |
int |
getMaximumIntegerDigits()
This method returns the maximum number of digits allowed in the integer portion of a number. |
int |
getMinimumFractionDigits()
This method returns the minimum number of digits allowed in the fraction portion of a number. |
int |
getMinimumIntegerDigits()
This method returns the minimum number of digits allowed in the integer portion of a number. |
static NumberFormat |
getNumberInstance()
This method returns a default instance for the specified locale. |
static NumberFormat |
getNumberInstance(Locale loc)
This method returns a general purpose number formatting and parsing class for the default locale. |
static NumberFormat |
getPercentInstance()
This method returns an instance of NumberFormat suitable
for formatting and parsing percentage values in the default locale. |
static NumberFormat |
getPercentInstance(Locale loc)
This method returns an instance of NumberFormat suitable
for formatting and parsing percentage values in the specified locale. |
int |
hashCode()
This method returns a hash value for this object. |
boolean |
isGroupingUsed()
This method tests whether or not grouping is in use. |
boolean |
isParseIntegerOnly()
This method tests whether or not only integer values should be parsed. |
Number |
parse(String sourceStr)
This method parses the specified string into a Number. |
abstract Number |
parse(String sourceStr,
ParsePosition pos)
This method parses the specified string into a Number. |
Object |
parseObject(String sourceStr,
ParsePosition pos)
This method parses the specified string into an Object. |
void |
setCurrency(Currency currency)
Sets the currency used by this number format when formatting currency values. |
void |
setGroupingUsed(boolean newValue)
This method sets the grouping behavior of this formatter. |
void |
setMaximumFractionDigits(int digits)
This method sets the maximum number of digits allowed in the fraction portion of a number to the specified value. |
void |
setMaximumIntegerDigits(int digits)
This method sets the maximum number of digits allowed in the integer portion of a number to the specified value. |
void |
setMinimumFractionDigits(int digits)
This method sets the minimum number of digits allowed in the fraction portion of a number to the specified value. |
void |
setMinimumIntegerDigits(int digits)
This method sets the minimum number of digits allowed in the integer portion of a number to the specified value. |
void |
setParseIntegerOnly(boolean value)
This method sets the parsing behavior of this object to parse only integers or not. |
| Methods inherited from class java.text.Format |
|---|
clone, format, formatToCharacterIterator, parseObject |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int INTEGER_FIELD
FieldPosition object
that will return the integer portion of a formatted number.
public static final int FRACTION_FIELD
FieldPosition object
that will return the fractional portion of a formatted number.
| Constructor Detail |
|---|
protected NumberFormat()
| Method Detail |
|---|
public final String format(long number)
long number.
number - The long to format.
public StringBuffer format(Object obj,
StringBuffer sbuf,
FieldPosition pos)
FormatObject into a String and
appends the String to a StringBuffer.
format in class Formatobj - The Object to format.sbuf - The StringBuffer to append to.pos - The desired FieldPosition, which is also
updated by this call.
StringBuffer.
public abstract StringBuffer format(double number,
StringBuffer sbuf,
FieldPosition pos)
double and appends it to
a StringBuffer.
number - The double to format.sbuf - The StringBuffer to append the formatted number
to.pos - The desired FieldPosition.
StringBuffer with the appended number.
public abstract StringBuffer format(long number,
StringBuffer sbuf,
FieldPosition pos)
long and appends it to
a StringBuffer.
number - The long to format.sbuf - The StringBuffer to append the formatted number
to.pos - The desired FieldPosition.
StringBuffer with the appended number.public boolean equals(Object obj)
true if the following conditions are met:
null.
NumberFormat.
Since this method does not test much, it is highly advised that concrete subclasses override this method.
equals in class Objectobj - The Object to test against equality with
this object.
true if the specified object is equal to
this object, false otherwise.Object.hashCode()public static Locale[] getAvailableLocales()
NumberFormat subclasses may be created.
public static final NumberFormat getCurrencyInstance()
NumberFormat suitable
for formatting and parsing currency values in the default locale.
NumberFormat for handling currencies.public static NumberFormat getCurrencyInstance(Locale loc)
NumberFormat suitable
for formatting and parsing currency values in the specified locale.
NumberFormat for handling currencies.public static final NumberFormat getInstance()
NumberFormat, but the
actual class returned is dependent on the locale.
NumberFormat class.public static NumberFormat getInstance(Locale loc)
NumberFormat, but the
actual class returned is dependent on the locale.
loc - The desired locale.
NumberFormat class.public int getMaximumFractionDigits()
public int getMaximumIntegerDigits()
public int getMinimumFractionDigits()
public int getMinimumIntegerDigits()
public static final NumberFormat getNumberInstance()
NumberFormat, but the
actual class returned is dependent on the locale.
NumberFormat class.public static NumberFormat getNumberInstance(Locale loc)
NumberFormat, but the actual class returned is dependent
on the locale.
public static final NumberFormat getIntegerInstance()
NumberFormat,
but the actual class returned is dependent on the locale.
public static NumberFormat getIntegerInstance(Locale locale)
NumberFormat,
but the actual class returned is dependent on the locale.
locale - the desired locale.
public static final NumberFormat getPercentInstance()
NumberFormat suitable
for formatting and parsing percentage values in the default locale.
NumberFormat for handling percentages.public static NumberFormat getPercentInstance(Locale loc)
NumberFormat suitable
for formatting and parsing percentage values in the specified locale.
loc - The desired locale.
NumberFormat for handling percentages.public int hashCode()
hashCode in class ObjectObject.equals(Object),
System.identityHashCode(Object)public boolean isGroupingUsed()
true if grouping is enabled,
false otherwise.public boolean isParseIntegerOnly()
true if only integers are parsed,
false otherwise.
public abstract Number parse(String sourceStr,
ParsePosition pos)
Number. This
will be a Long if possible, otherwise it will be a
Double. If no number can be parsed, no exception is
thrown. Instead, the parse position remains at its initial index.
sourceStr - The string to parse.pos - The desired ParsePosition.
Number
public Number parse(String sourceStr)
throws ParseException
Number. This
will be a Long if possible, otherwise it will be a
Double. If no number can be parsed, an exception will be
thrown.
sourceStr - The string to parse.
Number
ParseException - If no number can be parsed.
public final Object parseObject(String sourceStr,
ParsePosition pos)
Object. This
will be a Long if possible, otherwise it will be a
Double. If no number can be parsed, no exception is
thrown. Instead, the parse position remains at its initial index.
parseObject in class FormatsourceStr - The string to parse.pos - The desired ParsePosition.
Objectpublic void setGroupingUsed(boolean newValue)
newValue - true to enable grouping,
false to disable it.public void setMaximumFractionDigits(int digits)
digits - The new maximum fraction digits value.public void setMaximumIntegerDigits(int digits)
digits - The new maximum integer digits value.public void setMinimumFractionDigits(int digits)
digits - The new minimum fraction digits value.public void setMinimumIntegerDigits(int digits)
digits - The new minimum integer digits value.public void setParseIntegerOnly(boolean value)
value - true to parse only integers,
false otherwise.public final String format(double number)
double number.
number - The double to format.
public Currency getCurrency()
UnsupportedOperationException - If the number format class doesn't
implement currency formatting.public void setCurrency(Currency currency)
currency - The new currency to be used by this number format.
NullPointerException - If currenc is null.
UnsupportedOperationException - If the number format class doesn't
implement currency formatting.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||