Android
java.text
public abstract class

java.text.NumberFormat

java.lang.Object
java.text.Format Serializable Cloneable
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

Summary

Constants

      Value  
int  FRACTION_FIELD  Field constant.  0x00000001 
int  INTEGER_FIELD  Field constant.  0x00000000 

Public Constructors

            NumberFormat()
Constructs a new instance of DateFormat.

Public Methods

          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.
    final      String  format(long value)
Formats the specified long using the rules of this NumberFormat.
    final      String  format(double value)
Formats the specified double 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.
abstract          StringBuffer  format(double value, StringBuffer buffer, FieldPosition field)
Formats the double value into the specified StringBuffer 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.
      static    Locale[]  getAvailableLocales()
Gets the list of installed Locales which support NumberFormat.
          Currency  getCurrency()
Returns the currency used by this number format

This implementation throws UnsupportedOperationException, concrete sub classes should override if they support currency formatting.

    final  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.
    final  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.
      static    NumberFormat  getIntegerInstance(Locale locale)
Returns a NumberFormat for formatting and parsing integers for the specified Locale.
    final  static    NumberFormat  getIntegerInstance()
Returns a NumberFormat for formatting and parsing integers for the default 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(Locale locale)
Returns a NumberFormat for formatting and parsing numbers for the specified Locale.
    final  static    NumberFormat  getNumberInstance()
Returns a NumberFormat for formatting and parsing numbers for the default Locale.
    final  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.
    final      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
Methods inherited from class java.lang.Object

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

See Also

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

See Also

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

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

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.

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

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

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

public static Locale[] getAvailableLocales()

Gets the list of installed Locales which support NumberFormat.

Returns

  • an array of Locale

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.

Returns

  • a NumberFormat

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

public static final NumberFormat getInstance()

Returns a NumberFormat for formatting and parsing numbers for the default Locale.

Returns

  • a NumberFormat

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

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

public static final NumberFormat getIntegerInstance()

Returns a NumberFormat for formatting and parsing integers for the default Locale.

Returns

  • a NumberFormat

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.

Parameters

locale the Locale

Returns

  • a NumberFormat

public static final NumberFormat getNumberInstance()

Returns a NumberFormat for formatting and parsing numbers for the default Locale.

Returns

  • a NumberFormat

public static final NumberFormat getPercentInstance()

Returns a NumberFormat for formatting and parsing percentages for the default Locale.

Returns

  • a NumberFormat

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

public int hashCode()

Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Returns

  • the receiver's hash

See Also

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

public Number parse(String string)

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

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

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.

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
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56