Build 1.0_r1(from source)

java.text
Class NumberFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.NumberFormat
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
ChoiceFormat, DecimalFormat

public abstract class NumberFormat
extends Format

NumberFormat is the abstract superclass of Formats which format and parse Numbers.

See Also:
Serialized Form

Nested Class Summary
static class NumberFormat.Field
          The instances of this inner class are used as attribute keys and values in AttributedCharacterIterator that NumberFormat.formatToCharacterIterator() method returns.
 
Field Summary
static int FRACTION_FIELD
          Field constant.
static int INTEGER_FIELD
          Field constant.
 
Constructor Summary
NumberFormat()
          Constructs a new instance of DateFormat.
 
Method Summary
 Object clone()
          Returns a new NumberFormat with the same properties as this NumberFormat.
 boolean equals(Object object)
          Compares the specified object to this NumberFormat and answer if they are equal.
 String format(double value)
          Formats the specified double using the rules of this NumberFormat.
abstract  StringBuffer format(double value, StringBuffer buffer, FieldPosition field)
          Formats the double value into the specified StringBuffer using the rules of this NumberFormat.
 String format(long value)
          Formats the specified long using the rules of this NumberFormat.
abstract  StringBuffer format(long value, StringBuffer buffer, FieldPosition field)
          Formats the long value into the specified StringBuffer using the rules of this NumberFormat.
 StringBuffer format(Object object, StringBuffer buffer, FieldPosition field)
          Formats the specified object into the specified StringBuffer using the rules of this DateFormat.
static Locale[] getAvailableLocales()
          Gets the list of installed Locales which support NumberFormat.
 Currency getCurrency()
          Returns the currency used by this number format
static NumberFormat getCurrencyInstance()
          Returns a NumberFormat for formatting and parsing currency for the default Locale.
static NumberFormat getCurrencyInstance(Locale locale)
          Returns a NumberFormat for formatting and parsing currency for the specified Locale.
static NumberFormat getInstance()
          Returns a NumberFormat for formatting and parsing numbers for the default Locale.
static NumberFormat getInstance(Locale locale)
          Returns a NumberFormat for formatting and parsing numbers for the specified Locale.
(package private) static NumberFormat getInstance(Locale locale, String type)
           
static NumberFormat getIntegerInstance()
          Returns a NumberFormat for formatting and parsing integers for the default Locale.
static NumberFormat getIntegerInstance(Locale locale)
          Returns a NumberFormat for formatting and parsing integers for the specified Locale.
 int getMaximumFractionDigits()
          Returns the maximum number of fraction digits that are printed when formatting.
 int getMaximumIntegerDigits()
          Returns the maximum number of integer digits that are printed when formatting.
 int getMinimumFractionDigits()
          Returns the minimum number of fraction digits that are printed when formatting.
 int getMinimumIntegerDigits()
          Returns the minimum number of integer digits that are printed when formatting.
static NumberFormat getNumberInstance()
          Returns a NumberFormat for formatting and parsing numbers for the default Locale.
static NumberFormat getNumberInstance(Locale locale)
          Returns a NumberFormat for formatting and parsing numbers for the specified Locale.
(package private) static String getPattern(Locale locale, String type)
           
static NumberFormat getPercentInstance()
          Returns a NumberFormat for formatting and parsing percentages for the default Locale.
static NumberFormat getPercentInstance(Locale locale)
          Returns a NumberFormat for formatting and parsing percentages for the specified Locale.
 int hashCode()
          Returns an integer hash code for the receiver.
 boolean isGroupingUsed()
          Returns whether this NumberFormat formats and parses numbers using a grouping separator.
 boolean isParseIntegerOnly()
          Returns whether this NumberFormat only parses integer numbers.
 Number parse(String string)
          Parse a Number from the specified String using the rules of this NumberFormat.
abstract  Number parse(String string, ParsePosition position)
          Parse a Number from the specified String starting at the index specified by the ParsePosition.
 Object parseObject(String string, ParsePosition position)
          Parse a Number from the specified String starting at the index specified by the ParsePosition.
 void setCurrency(Currency currency)
          Sets the currency used by this number format when formatting currency values.
 void setGroupingUsed(boolean value)
          Sets whether this NumberFormat formats and parses numbers using a grouping separator.
 void setMaximumFractionDigits(int value)
          Sets the maximum number of fraction digits that are printed when formatting.
 void setMaximumIntegerDigits(int value)
          Used to specify the new maximum count of integer digits that are printed when formatting.
 void setMinimumFractionDigits(int value)
          Sets the minimum number of fraction digits that are printed when formatting.
 void setMinimumIntegerDigits(int value)
          Sets the minimum number of integer digits that are printed when formatting.
 void setParseIntegerOnly(boolean value)
          Specifies if this NumberFormat should only parse numbers as integers or else as any kind of number.
 
Methods inherited from class java.text.Format
convertPattern, format, formatToCharacterIterator, getBundle, parseObject, upTo, upToWithQuotes
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTEGER_FIELD

public static final int INTEGER_FIELD
Field constant.

See Also:
Constant Field Values

FRACTION_FIELD

public static final int FRACTION_FIELD
Field constant.

See Also:
Constant Field Values
Constructor Detail

NumberFormat

public NumberFormat()
Constructs a new instance of DateFormat.

Method Detail

clone

public Object clone()
Returns a new NumberFormat with the same properties as this NumberFormat.

Overrides:
clone in class Format
Returns:
a shallow copy of this NumberFormat
See Also:
Cloneable

equals

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.

Overrides:
equals in class Object
Parameters:
object - the object to compare with this object
Returns:
true if the specified object is equal to this NumberFormat, false otherwise
See Also:
hashCode()

format

public final String format(double value)
Formats the specified double using the rules of this NumberFormat.

Parameters:
value - the double to format
Returns:
the formatted String

format

public abstract StringBuffer format(double value,
                                    StringBuffer buffer,
                                    FieldPosition field)
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

format

public final String format(long value)
Formats the specified long using the rules of this NumberFormat.

Parameters:
value - the long to format
Returns:
the formatted String

format

public abstract StringBuffer format(long value,
                                    StringBuffer buffer,
                                    FieldPosition field)
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

format

public StringBuffer format(Object object,
                           StringBuffer buffer,
                           FieldPosition field)
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.

Specified by:
format in class Format
Parameters:
object - the object to format, must be a Number
buffer - the StringBuffer
field - the FieldPosition
Returns:
the StringBuffer parameter buffer
Throws:
IllegalArgumentException - when the object is not a Number

getAvailableLocales

public static Locale[] getAvailableLocales()
Gets the list of installed Locales which support NumberFormat.

Returns:
an array of Locale

getCurrency

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
Throws:
UnsupportedOperationException

getCurrencyInstance

public static final NumberFormat getCurrencyInstance()
Returns a NumberFormat for formatting and parsing currency for the default Locale.

Returns:
a NumberFormat

getCurrencyInstance

public static NumberFormat getCurrencyInstance(Locale locale)
Returns a NumberFormat for formatting and parsing currency for the specified Locale.

Parameters:
locale - the Locale
Returns:
a NumberFormat

getIntegerInstance

public static final NumberFormat getIntegerInstance()
Returns a NumberFormat for formatting and parsing integers for the default Locale.

Returns:
a NumberFormat

getIntegerInstance

public static NumberFormat getIntegerInstance(Locale locale)
Returns a NumberFormat for formatting and parsing integers for the specified Locale.

Parameters:
locale - the Locale
Returns:
a NumberFormat

getInstance

public static final NumberFormat getInstance()
Returns a NumberFormat for formatting and parsing numbers for the default Locale.

Returns:
a NumberFormat

getInstance

public static NumberFormat getInstance(Locale locale)
Returns a NumberFormat for formatting and parsing numbers for the specified Locale.

Parameters:
locale - the Locale
Returns:
a NumberFormat

getInstance

static NumberFormat getInstance(Locale locale,
                                String type)

getMaximumFractionDigits

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

getMaximumIntegerDigits

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

getMinimumFractionDigits

public int getMinimumFractionDigits()
Returns the minimum number of fraction digits that are printed when formatting.

Returns:
the minimum number of fraction digits

getMinimumIntegerDigits

public int getMinimumIntegerDigits()
Returns the minimum number of integer digits that are printed when formatting.

Returns:
the minimum number of integer digits

getNumberInstance

public static final NumberFormat getNumberInstance()
Returns a NumberFormat for formatting and parsing numbers for the default Locale.

Returns:
a NumberFormat

getNumberInstance

public static NumberFormat getNumberInstance(Locale locale)
Returns a NumberFormat for formatting and parsing numbers for the specified Locale.

Parameters:
locale - the Locale
Returns:
a NumberFormat

getPattern

static String getPattern(Locale locale,
                         String type)

getPercentInstance

public static final NumberFormat getPercentInstance()
Returns a NumberFormat for formatting and parsing percentages for the default Locale.

Returns:
a NumberFormat

getPercentInstance

public static NumberFormat getPercentInstance(Locale locale)
Returns a NumberFormat for formatting and parsing percentages for the specified Locale.

Parameters:
locale - the Locale
Returns:
a NumberFormat

hashCode

public int hashCode()
Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

isGroupingUsed

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

isParseIntegerOnly

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

public Number parse(String string)
             throws ParseException
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
Throws:
ParseException - when an error occurs during parsing

parse

public abstract Number parse(String string,
                             ParsePosition position)
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

parseObject

public final Object parseObject(String string,
                                ParsePosition position)
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.

Specified by:
parseObject in class Format
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

setCurrency

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
Throws:
UnsupportedOperationException

setGroupingUsed

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

setMaximumFractionDigits

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

setMaximumIntegerDigits

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

setMinimumFractionDigits

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

setMinimumIntegerDigits

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

setParseIntegerOnly

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

Build 1.0_r1(from source)

Please submit a feedback, bug or feature