java.text
public abstract class NumberFormat extends Format implements Cloneable
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
.
UNKNOWN: March 4, 1999
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 | |
---|---|
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(long number)
This method is a specialization of the format method that performs
a simple formatting of the specified long number.
|
StringBuffer | format(Object obj, StringBuffer sbuf, FieldPosition pos) |
abstract StringBuffer | format(double number, StringBuffer sbuf, FieldPosition pos)
This method formats the specified double and appends it to
a StringBuffer .
|
abstract StringBuffer | format(long number, StringBuffer sbuf, FieldPosition pos)
This method formats the specified long and appends it to
a StringBuffer .
|
String | format(double number)
This method is a specialization of the format method that performs
a simple formatting of the specified double number.
|
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.
|
abstract Number | parse(String sourceStr, ParsePosition pos)
This method parses the specified string into a Number . |
Number | parse(String sourceStr)
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.
|
FieldPosition
object
that will return the fractional portion of a formatted number.FieldPosition
object
that will return the integer portion of a formatted number.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.
Parameters: obj The Object
to test against equality with
this object.
Returns: true
if the specified object is equal to
this object, false
otherwise.
long
number.
Parameters: number The long
to format.
Returns: The formatted number
UNKNOWN: this method was final in releases before 1.5
double
and appends it to
a StringBuffer
.
Parameters: number The double
to format. sbuf The StringBuffer
to append the formatted number
to. pos The desired FieldPosition
.
Returns: The StringBuffer
with the appended number.
long
and appends it to
a StringBuffer
.
Parameters: number The long
to format. sbuf The StringBuffer
to append the formatted number
to. pos The desired FieldPosition
.
Returns: The StringBuffer
with the appended number.
double
number.
Parameters: number The double
to format.
Returns: The formatted number
NumberFormat
subclasses may be created.
Returns: The list of available locales.
Returns: The used currency object, or null.
Throws: UnsupportedOperationException If the number format class doesn't implement currency formatting.
Since: 1.4
NumberFormat
suitable
for formatting and parsing currency values in the default locale.
Returns: An instance of NumberFormat
for handling currencies.
NumberFormat
suitable
for formatting and parsing currency values in the specified locale.
Returns: An instance of NumberFormat
for handling currencies.
NumberFormat
, but the
actual class returned is dependent on the locale.
Returns: An instance of the default NumberFormat
class.
NumberFormat
, but the
actual class returned is dependent on the locale.
Parameters: loc The desired locale.
Returns: An instance of the default NumberFormat
class.
NumberFormat
,
but the actual class returned is dependent on the locale.
Returns: An instance of an integer number formatter for the default locale.
Since: 1.4
NumberFormat
,
but the actual class returned is dependent on the locale.
Parameters: locale the desired locale.
Returns: An instance of an integer number formatter for the desired locale.
Since: 1.4
Returns: The maximum number of digits allowed in the fraction portion of a number.
Returns: The maximum number of digits allowed in the integer portion of a number.
Returns: The minimum number of digits allowed in the fraction portion of a number.
Returns: The minimum number of digits allowed in the integer portion of a number.
NumberFormat
, but the
actual class returned is dependent on the locale.
Returns: An instance of the default NumberFormat
class.
NumberFormat
, but the actual class returned is dependent
on the locale.
Returns: An instance of a generic number formatter for the default locale.
NumberFormat
suitable
for formatting and parsing percentage values in the default locale.
Returns: An instance of NumberFormat
for handling percentages.
NumberFormat
suitable
for formatting and parsing percentage values in the specified locale.
Parameters: loc The desired locale.
Returns: An instance of NumberFormat
for handling percentages.
Returns: The hash code.
Returns: true
if grouping is enabled,
false
otherwise.
Returns: true
if only integers are parsed,
false
otherwise.
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.
Parameters: sourceStr The string to parse. pos The desired ParsePosition
.
Returns: The parsed Number
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.
Parameters: sourceStr The string to parse.
Returns: The parsed Number
Throws: ParseException If no number can be parsed.
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.
Parameters: sourceStr The string to parse. pos The desired ParsePosition
.
Returns: The parsed Object
Parameters: currency The new currency to be used by this number format.
Throws: NullPointerException If currenc is null. UnsupportedOperationException If the number format class doesn't implement currency formatting.
Since: 1.4
Parameters: newValue true
to enable grouping,
false
to disable it.
Parameters: digits The new maximum fraction digits value.
Parameters: digits The new maximum integer digits value.
Parameters: digits The new minimum fraction digits value.
Parameters: digits The new minimum integer digits value.
Parameters: value true
to parse only integers,
false
otherwise.