java.text
public
abstract
class
java.text.NumberFormat
NumberFormat is the abstract superclass of Formats which format and parse
Numbers.
Nested Classes
NumberFormat.Field |
The instances of this inner class are used as attribute keys and values
in AttributedCharacterIterator that
NumberFormat.formatToCharacterIterator() method returns. |
Known Direct Subclasses
ChoiceFormat |
ChoiceFormat is used to associate strings with ranges of double values. |
DecimalFormat |
DecimalFormat is used to format and parse numbers, both integers and
fractions, based on a pattern. |
Summary
Constants
Public Constructors
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
FRACTION_FIELD
Field constant.
Constant Value:
1
(0x00000001)
public
static
final
int
INTEGER_FIELD
Field constant.
Constant Value:
0
(0x00000000)
Public Constructors
public
NumberFormat()
Constructs a new instance of DateFormat.
Public Methods
public
Object
clone()
Returns a new NumberFormat with the same properties as this NumberFormat.
Returns
- a shallow copy of this NumberFormat
public
boolean
equals(Object object)
Compares the specified object to this NumberFormat and answer if they are
equal. The object must be an instance of NumberFormat and have the same
properties.
Parameters
object
| the object to compare with this object |
Returns
- true if the specified object is equal to this NumberFormat, false
otherwise
public
final
String
format(long value)
Formats the specified long using the rules of this NumberFormat.
public
final
String
format(double value)
Formats the specified double using the rules of this NumberFormat.
Parameters
value
| the double to format |
Formats the specified object into the specified StringBuffer using the
rules of this DateFormat. If the field specified by the FieldPosition is
formatted, set the begin and end index of the formatted field in the
FieldPosition.
Parameters
object
| the object to format, must be a Number |
buffer
| the StringBuffer |
field
| the FieldPosition |
Returns
- the StringBuffer parameter
buffer
Formats the double value into the specified StringBuffer using the rules
of this NumberFormat. If the field specified by the FieldPosition is
formatted, set the begin and end index of the formatted field in the
FieldPosition.
Parameters
value
| the double to format |
buffer
| the StringBuffer |
field
| the FieldPosition |
Returns
- the StringBuffer parameter
buffer
Formats the long value into the specified StringBuffer using the rules of
this NumberFormat. If the field specified by the FieldPosition is
formatted, set the begin and end index of the formatted field in the
FieldPosition.
Parameters
value
| the long to format |
buffer
| the StringBuffer |
field
| the FieldPosition |
Returns
- the StringBuffer parameter
buffer
public
static
Locale[]
getAvailableLocales()
Gets the list of installed Locales which support NumberFormat.
public
Currency
getCurrency()
Returns the currency used by this number format
This implementation throws UnsupportedOperationException, concrete sub
classes should override if they support currency formatting.
Returns
- currency currency that was set in getInstance() or in
setCurrency(), or null
public
static
final
NumberFormat
getCurrencyInstance()
Returns a NumberFormat for formatting and parsing currency for the
default Locale.
public
static
NumberFormat
getCurrencyInstance(Locale locale)
Returns a NumberFormat for formatting and parsing currency for the
specified Locale.
public
static
final
NumberFormat
getInstance()
Returns a NumberFormat for formatting and parsing numbers for the default
Locale.
Returns a NumberFormat for formatting and parsing numbers for the
specified Locale.
public
static
NumberFormat
getIntegerInstance(Locale locale)
Returns a NumberFormat for formatting and parsing integers for the
specified Locale.
public
static
final
NumberFormat
getIntegerInstance()
Returns a NumberFormat for formatting and parsing integers for the
default Locale.
public
int
getMaximumFractionDigits()
Returns the maximum number of fraction digits that are printed when
formatting. If the maximum is less than the number of fraction digits,
the least significant digits are truncated.
Returns
- the maximum number of fraction digits
public
int
getMaximumIntegerDigits()
Returns the maximum number of integer digits that are printed when
formatting. If the maximum is less than the number of integer digits, the
most significant digits are truncated.
Returns
- the maximum number of integer digits
public
int
getMinimumFractionDigits()
Returns the minimum number of fraction digits that are printed when
formatting.
Returns
- the minimum number of fraction digits
public
int
getMinimumIntegerDigits()
Returns the minimum number of integer digits that are printed when
formatting.
Returns
- the minimum number of integer digits
public
static
NumberFormat
getNumberInstance(Locale locale)
Returns a NumberFormat for formatting and parsing numbers for the
specified Locale.
public
static
final
NumberFormat
getNumberInstance()
Returns a NumberFormat for formatting and parsing numbers for the default
Locale.
public
static
final
NumberFormat
getPercentInstance()
Returns a NumberFormat for formatting and parsing percentages for the
default Locale.
public
static
NumberFormat
getPercentInstance(Locale locale)
Returns a NumberFormat for formatting and parsing percentages for the
specified Locale.
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
public
boolean
isGroupingUsed()
Returns whether this NumberFormat formats and parses numbers using a
grouping separator.
Returns
- true when a grouping separator is used, false otherwise
public
boolean
isParseIntegerOnly()
Returns whether this NumberFormat only parses integer numbers. Parsing
stops if a decimal separator is encountered.
Returns
- true if this NumberFormat only parses integers, false for parsing
integers or fractions
Parse a Number from the specified String using the rules of this
NumberFormat.
Parameters
string
| the String to parse |
Returns
- the Number resulting from the parse
Parse a Number from the specified String starting at the index specified
by the ParsePosition. If the string is successfully parsed, the index of
the ParsePosition is updated to the index following the parsed text.
Parameters
string
| the String to parse |
position
| the ParsePosition, updated on return with the index following
the parsed text, or on error the index is unchanged and the
error index is set to the index where the error occurred |
Returns
- the Number resulting from the parse, or null if there is an error
Parse a Number from the specified String starting at the index specified
by the ParsePosition. If the string is successfully parsed, the index of
the ParsePosition is updated to the index following the parsed text.
Parameters
string
| the String to parse |
position
| the ParsePosition, updated on return with the index following
the parsed text, or on error the index is unchanged and the
error index is set to the index where the error occurred |
Returns
- the Number resulting from the parse, or null if there is an error
public
void
setCurrency(Currency currency)
Sets the currency used by this number format when formatting currency
values.
The min and max fraction digits remain the same.
This implementation throws UnsupportedOperationException, concrete sub
classes should override if they support currency formatting.
Parameters
currency
| the new Currency |
public
void
setGroupingUsed(boolean value)
Sets whether this NumberFormat formats and parses numbers using a
grouping separator.
Parameters
value
| true when a grouping separator is used, false otherwise
|
public
void
setMaximumFractionDigits(int value)
Sets the maximum number of fraction digits that are printed when
formatting. If the maximum is less than the number of fraction digits,
the least significant digits are truncated.
Parameters
value
| the maximum number of fraction digits
|
public
void
setMaximumIntegerDigits(int value)
Used to specify the new maximum count of integer digits that are printed
when formatting. If the maximum is less than the number of integer
digits, the most significant digits are truncated.
Parameters
value
| the new maximum number of integer numerals for display
|
public
void
setMinimumFractionDigits(int value)
Sets the minimum number of fraction digits that are printed when
formatting.
Parameters
value
| the minimum number of fraction digits
|
public
void
setMinimumIntegerDigits(int value)
Sets the minimum number of integer digits that are printed when
formatting.
Parameters
value
| the minimum number of integer digits
|
public
void
setParseIntegerOnly(boolean value)
Specifies if this NumberFormat should only parse numbers as integers or
else as any kind of number. If this is called with a
true
value then subsequent parsing attempts will stop if a decimal separator
is encountered.
Parameters
value
| true to only parse integers, false
to parse integers and fractions
|