Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.text.Format
java.text.NumberFormat
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 |
Nested classes/interfaces inherited from class java.text.Format | |
Format.Field |
Field Summary | |
static int |
|
static int |
|
Constructor Summary | |
|
Method Summary | |
boolean | |
String |
|
abstract StringBuffer |
|
StringBuffer |
|
String |
|
abstract StringBuffer |
|
static Locale[] |
|
Currency |
|
static NumberFormat |
|
static NumberFormat |
|
static NumberFormat |
|
static NumberFormat |
|
static NumberFormat |
|
static NumberFormat |
|
int |
|
int |
|
int |
|
int |
|
static NumberFormat |
|
static NumberFormat |
|
static NumberFormat |
|
static NumberFormat |
|
int |
|
boolean |
|
boolean |
|
Number | |
abstract Number |
|
Object |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.text.Format | |
clone , format , format , formatToCharacterIterator , parseObject , parseObject |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final int FRACTION_FIELD
This is a constant used to create aFieldPosition
object that will return the fractional portion of a formatted number.
- Field Value:
- 1
public static final int INTEGER_FIELD
This is a constant used to create aFieldPosition
object that will return the integer portion of a formatted number.
- Field Value:
- 0
public boolean equals(Object obj)
This method tests the specified object for equality against this object. This will betrue
if the following conditions are met:
- The specified object is not
null
.- The specified object is an instance of
NumberFormat
.Since this method does not test much, it is highly advised that concrete subclasses override this method.
- Parameters:
obj
- TheObject
to test against equality with this object.
- Returns:
true
if the specified object is equal to this object,false
otherwise.
public final String format(double number)
This method is a specialization of the format method that performs a simple formatting of the specifieddouble
number.
- Parameters:
number
- Thedouble
to format.
- Returns:
- The formatted number
public abstract StringBuffer format(double number, StringBuffer sbuf, FieldPosition pos)
This method formats the specifieddouble
and appends it to aStringBuffer
.
- Parameters:
number
- Thedouble
to format.sbuf
- TheStringBuffer
to append the formatted number to.pos
- The desiredFieldPosition
.
- Returns:
- The
StringBuffer
with the appended number.
public final String format(long number)
This method is a specialization of the format method that performs a simple formatting of the specifiedlong
number.
- Parameters:
number
- Thelong
to format.
- Returns:
- The formatted number
public abstract StringBuffer format(long number, StringBuffer sbuf, FieldPosition pos)
This method formats the specifiedlong
and appends it to aStringBuffer
.
- Parameters:
number
- Thelong
to format.sbuf
- TheStringBuffer
to append the formatted number to.pos
- The desiredFieldPosition
.
- Returns:
- The
StringBuffer
with the appended number.
public static Locale[] getAvailableLocales()
This method returns a list of locales for which concrete instances ofNumberFormat
subclasses may be created.
- Returns:
- The list of available locales.
public Currency getCurrency()
Returns the currency used by this number format when formatting currency values. The default implementation throws UnsupportedOperationException.
- Returns:
- The used currency object, or null.
- Throws:
UnsupportedOperationException
- If the number format class doesn't implement currency formatting.
- Since:
- 1.4
public static final NumberFormat getCurrencyInstance()
This method returns an instance ofNumberFormat
suitable for formatting and parsing currency values in the default locale.
- Returns:
- An instance of
NumberFormat
for handling currencies.
public static NumberFormat getCurrencyInstance(Locale loc)
This method returns an instance ofNumberFormat
suitable for formatting and parsing currency values in the specified locale.
- Returns:
- An instance of
NumberFormat
for handling currencies.
public static final NumberFormat getInstance()
This method returns a default instance for the default locale. This will be a concrete subclass ofNumberFormat
, but the actual class returned is dependent on the locale.
- Returns:
- An instance of the default
NumberFormat
class.
public static NumberFormat getInstance(Locale loc)
This method returns a default instance for the specified locale. This will be a concrete subclass ofNumberFormat
, but the actual class returned is dependent on the locale.
- Parameters:
loc
- The desired locale.
- Returns:
- An instance of the default
NumberFormat
class.
public static final NumberFormat getIntegerInstance()
This method returns an integer formatting and parsing class for the default locale. This will be a concrete subclass ofNumberFormat
, 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
public static NumberFormat getIntegerInstance(Locale locale)
This method returns an integer formatting and parsing class for the default locale. This will be a concrete subclass ofNumberFormat
, 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
public int getMaximumFractionDigits()
This method returns the maximum number of digits allowed in the fraction portion of a number.
- Returns:
- The maximum number of digits allowed in the fraction portion of a number.
public int getMaximumIntegerDigits()
This method returns the maximum number of digits allowed in the integer portion of a number.
- Returns:
- The maximum number of digits allowed in the integer portion of a number.
public int getMinimumFractionDigits()
This method returns the minimum number of digits allowed in the fraction portion of a number.
- Returns:
- The minimum number of digits allowed in the fraction portion of a number.
public int getMinimumIntegerDigits()
This method returns the minimum number of digits allowed in the integer portion of a number.
- Returns:
- The minimum number of digits allowed in the integer portion of a number.
public static final NumberFormat getNumberInstance()
This method returns a default instance for the specified locale. This will be a concrete subclass ofNumberFormat
, but the actual class returned is dependent on the locale.
- Returns:
- An instance of the default
NumberFormat
class.
public static NumberFormat getNumberInstance(Locale loc)
This method returns a general purpose number formatting and parsing class for the default locale. This will be a concrete subclass ofNumberFormat
, but the actual class returned is dependent on the locale.
- Returns:
- An instance of a generic number formatter for the default locale.
public static final NumberFormat getPercentInstance()
This method returns an instance ofNumberFormat
suitable for formatting and parsing percentage values in the default locale.
- Returns:
- An instance of
NumberFormat
for handling percentages.
public static NumberFormat getPercentInstance(Locale loc)
This method returns an instance ofNumberFormat
suitable for formatting and parsing percentage values in the specified locale.
- Parameters:
loc
- The desired locale.
- Returns:
- An instance of
NumberFormat
for handling percentages.
public int hashCode()
This method returns a hash value for this object.
- Returns:
- The hash code.
public boolean isGroupingUsed()
This method tests whether or not grouping is in use. Grouping is a method of marking separations in numbers, such as thousand separators in the US English locale. The grouping positions and symbols are all locale specific. As an example, with grouping disabled, the number one million would appear as "1000000". With grouping enabled, this number might appear as "1,000,000". (Both of these assume the US English locale).
- Returns:
true
if grouping is enabled,false
otherwise.
public boolean isParseIntegerOnly()
This method tests whether or not only integer values should be parsed. If this class is parsing only integers, parsing stops at the decimal point.
- Returns:
true
if only integers are parsed,false
otherwise.
public Number parse(String sourceStr) throws ParseException
This method parses the specified string into aNumber
. This will be aLong
if possible, otherwise it will be aDouble
. 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.
public abstract Number parse(String sourceStr, ParsePosition pos)
This method parses the specified string into aNumber
. This will be aLong
if possible, otherwise it will be aDouble
. 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 desiredParsePosition
.
- Returns:
- The parsed
Number
public final Object parseObject(String sourceStr, ParsePosition pos)
This method parses the specified string into anObject
. This will be aLong
if possible, otherwise it will be aDouble
. If no number can be parsed, no exception is thrown. Instead, the parse position remains at its initial index.
- Overrides:
- parseObject in interface Format
- Parameters:
sourceStr
- The string to parse.pos
- The desiredParsePosition
.
- Returns:
- The parsed
Object
public void setCurrency(Currency currency)
Sets the currency used by this number format when formatting currency values. The default implementation throws UnsupportedOperationException.
- 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
public void setGroupingUsed(boolean newValue)
This method sets the grouping behavior of this formatter. Grouping is a method of marking separations in numbers, such as thousand separators in the US English locale. The grouping positions and symbols are all locale specific. As an example, with grouping disabled, the number one million would appear as "1000000". With grouping enabled, this number might appear as "1,000,000". (Both of these assume the US English locale).
- Parameters:
newValue
-true
to enable grouping,false
to disable it.
public void setMaximumFractionDigits(int digits)
This method sets the maximum number of digits allowed in the fraction portion of a number to the specified value. If this is less than the current minimum allowed digits, the minimum allowed digits value will be lowered to be equal to the new maximum allowed digits value.
- Parameters:
digits
- The new maximum fraction digits value.
public void setMaximumIntegerDigits(int digits)
This method sets the maximum number of digits allowed in the integer portion of a number to the specified value. If this is less than the current minimum allowed digits, the minimum allowed digits value will be lowered to be equal to the new maximum allowed digits value.
- Parameters:
digits
- The new maximum integer digits value.
public void setMinimumFractionDigits(int digits)
This method sets the minimum number of digits allowed in the fraction portion of a number to the specified value. If this is greater than the current maximum allowed digits, the maximum allowed digits value will be raised to be equal to the new minimum allowed digits value.
- Parameters:
digits
- The new minimum fraction digits value.
public void setMinimumIntegerDigits(int digits)
This method sets the minimum number of digits allowed in the integer portion of a number to the specified value. If this is greater than the current maximum allowed digits, the maximum allowed digits value will be raised to be equal to the new minimum allowed digits value.
- Parameters:
digits
- The new minimum integer digits value.
public void setParseIntegerOnly(boolean value)
This method sets the parsing behavior of this object to parse only integers or not.
- Parameters:
value
-true
to parse only integers,false
otherwise.