java.text
Class NumberFormat

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

public abstract class NumberFormat
extends Format sample code for java.text.Format definition code for java.text.Format

NumberFormat is the abstract base class for all number formats. This class provides the interface for formatting and parsing numbers. NumberFormat also provides methods for determining which locales have number formats, and what their names are.

NumberFormat helps you to format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal.

To format a number for the current Locale, use one of the factory class methods:

  myString = NumberFormat.getInstance().format(myNumber);
 
If you are formatting multiple numbers, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.
 NumberFormat nf = NumberFormat.getInstance();
 for (int i = 0; i < a.length; ++i) {
     output.println(nf.format(myNumber[i]) + "; ");
 }
 
To format a number for a different Locale, specify it in the call to getInstance.
 NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
 
You can also use a NumberFormat to parse numbers:
 myNumber = nf.parse(myString);
 
Use getInstance or getNumberInstance to get the normal number format. Use getIntegerInstance to get an integer number format. Use getCurrencyInstance to get the currency number format. And use getPercentInstance to get a format for displaying percentages. With this format, a fraction like 0.53 is displayed as 53%.

You can also control the display of numbers with such methods as setMinimumFractionDigits. If you want even more control over the format or parsing, or want to give your users more control, you can try casting the NumberFormat you get from the factory methods to a DecimalFormat. This will work for the vast majority of locales; just remember to put it in a try block in case you encounter an unusual one.

NumberFormat and DecimalFormat are designed such that some controls work for formatting and others work for parsing. The following is the detailed description for each these control methods,

setParseIntegerOnly : only affects parsing, e.g. if true, "3456.78" -> 3456 (and leaves the parse position just after index 6) if false, "3456.78" -> 3456.78 (and leaves the parse position just after index 8) This is independent of formatting. If you want to not show a decimal point where there might be no digits after the decimal point, use setDecimalSeparatorAlwaysShown.

setDecimalSeparatorAlwaysShown : only affects formatting, and only where there might be no digits after the decimal point, such as with a pattern like "#,##0.##", e.g., if true, 3456.00 -> "3,456." if false, 3456.00 -> "3456" This is independent of parsing. If you want parsing to stop at the decimal point, use setParseIntegerOnly.

You can also use forms of the parse and format methods with ParsePosition and FieldPosition to allow you to:

For example, you can align numbers in two ways:
  1. If you are using a monospaced font with spacing for alignment, you can pass the FieldPosition in your format call, with field = INTEGER_FIELD. On output, getEndIndex will be set to the offset between the last character of the integer and the decimal. Add (desiredSpaceCount - getEndIndex) spaces at the front of the string.
  2. If you are using proportional fonts, instead of padding with spaces, measure the width of the string in pixels from the start to getEndIndex. Then move the pen by (desiredPixelWidth - widthToAlignmentPoint) before drawing the text. It also works where there is no decimal, but possibly additional characters at the end, e.g., with parentheses in negative numbers: "(12)" for -12.

Synchronization

Number formats are generally not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.

See Also:
DecimalFormat sample code for java.text.DecimalFormat definition code for java.text.DecimalFormat , ChoiceFormat sample code for java.text.ChoiceFormat definition code for java.text.ChoiceFormat , Serialized Form

Nested Class Summary
static class NumberFormat.Field sample code for java.text.NumberFormat.Field definition code for java.text.NumberFormat.Field
          Defines constants that are used as attribute keys in the AttributedCharacterIterator returned from NumberFormat.formatToCharacterIterator and as field identifiers in FieldPosition.
 
Field Summary
static int FRACTION_FIELD sample code for java.text.NumberFormat.FRACTION_FIELD definition code for java.text.NumberFormat.FRACTION_FIELD
          Field constant used to construct a FieldPosition object.
static int INTEGER_FIELD sample code for java.text.NumberFormat.INTEGER_FIELD definition code for java.text.NumberFormat.INTEGER_FIELD
          Field constant used to construct a FieldPosition object.
 
Constructor Summary
NumberFormat sample code for java.text.NumberFormat.NumberFormat() definition code for java.text.NumberFormat.NumberFormat() ()
           
 
Method Summary
 Object sample code for java.lang.Object definition code for java.lang.Object clone sample code for java.text.NumberFormat.clone() definition code for java.text.NumberFormat.clone() ()
          Overrides Cloneable
 boolean equals sample code for java.text.NumberFormat.equals(java.lang.Object) definition code for java.text.NumberFormat.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Overrides equals
 String sample code for java.lang.String definition code for java.lang.String format sample code for java.text.NumberFormat.format(double) definition code for java.text.NumberFormat.format(double) (double number)
          Specialization of format.
abstract  StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer format sample code for java.text.NumberFormat.format(double, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.NumberFormat.format(double, java.lang.StringBuffer, java.text.FieldPosition) (double number, StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  toAppendTo, FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition  pos)
          Specialization of format.
 String sample code for java.lang.String definition code for java.lang.String format sample code for java.text.NumberFormat.format(long) definition code for java.text.NumberFormat.format(long) (long number)
          Specialization of format.
abstract  StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer format sample code for java.text.NumberFormat.format(long, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.NumberFormat.format(long, java.lang.StringBuffer, java.text.FieldPosition) (long number, StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  toAppendTo, FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition  pos)
          Specialization of format.
 StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer format sample code for java.text.NumberFormat.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.NumberFormat.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) (Object sample code for java.lang.Object definition code for java.lang.Object  number, StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  toAppendTo, FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition  pos)
          Formats a number and appends the resulting text to the given string buffer.
static Locale sample code for java.util.Locale definition code for java.util.Locale [] getAvailableLocales sample code for java.text.NumberFormat.getAvailableLocales() definition code for java.text.NumberFormat.getAvailableLocales() ()
          Returns an array of all locales for which the get*Instance methods of this class can return localized instances.
 Currency sample code for java.util.Currency definition code for java.util.Currency getCurrency sample code for java.text.NumberFormat.getCurrency() definition code for java.text.NumberFormat.getCurrency() ()
          Gets the currency used by this number format when formatting currency values.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getCurrencyInstance sample code for java.text.NumberFormat.getCurrencyInstance() definition code for java.text.NumberFormat.getCurrencyInstance() ()
          Returns a currency format for the current default locale.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getCurrencyInstance sample code for java.text.NumberFormat.getCurrencyInstance(java.util.Locale) definition code for java.text.NumberFormat.getCurrencyInstance(java.util.Locale) (Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
          Returns a currency format for the specified locale.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getInstance sample code for java.text.NumberFormat.getInstance() definition code for java.text.NumberFormat.getInstance() ()
          Returns a general-purpose number format for the current default locale.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getInstance sample code for java.text.NumberFormat.getInstance(java.util.Locale) definition code for java.text.NumberFormat.getInstance(java.util.Locale) (Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
          Returns a general-purpose number format for the specified locale.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getIntegerInstance sample code for java.text.NumberFormat.getIntegerInstance() definition code for java.text.NumberFormat.getIntegerInstance() ()
          Returns an integer number format for the current default locale.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getIntegerInstance sample code for java.text.NumberFormat.getIntegerInstance(java.util.Locale) definition code for java.text.NumberFormat.getIntegerInstance(java.util.Locale) (Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
          Returns an integer number format for the specified locale.
 int getMaximumFractionDigits sample code for java.text.NumberFormat.getMaximumFractionDigits() definition code for java.text.NumberFormat.getMaximumFractionDigits() ()
          Returns the maximum number of digits allowed in the fraction portion of a number.
 int getMaximumIntegerDigits sample code for java.text.NumberFormat.getMaximumIntegerDigits() definition code for java.text.NumberFormat.getMaximumIntegerDigits() ()
          Returns the maximum number of digits allowed in the integer portion of a number.
 int getMinimumFractionDigits sample code for java.text.NumberFormat.getMinimumFractionDigits() definition code for java.text.NumberFormat.getMinimumFractionDigits() ()
          Returns the minimum number of digits allowed in the fraction portion of a number.
 int getMinimumIntegerDigits sample code for java.text.NumberFormat.getMinimumIntegerDigits() definition code for java.text.NumberFormat.getMinimumIntegerDigits() ()
          Returns the minimum number of digits allowed in the integer portion of a number.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getNumberInstance sample code for java.text.NumberFormat.getNumberInstance() definition code for java.text.NumberFormat.getNumberInstance() ()
          Returns a general-purpose number format for the current default locale.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getNumberInstance sample code for java.text.NumberFormat.getNumberInstance(java.util.Locale) definition code for java.text.NumberFormat.getNumberInstance(java.util.Locale) (Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
          Returns a general-purpose number format for the specified locale.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getPercentInstance sample code for java.text.NumberFormat.getPercentInstance() definition code for java.text.NumberFormat.getPercentInstance() ()
          Returns a percentage format for the current default locale.
static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat getPercentInstance sample code for java.text.NumberFormat.getPercentInstance(java.util.Locale) definition code for java.text.NumberFormat.getPercentInstance(java.util.Locale) (Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
          Returns a percentage format for the specified locale.
 int hashCode sample code for java.text.NumberFormat.hashCode() definition code for java.text.NumberFormat.hashCode() ()
          Overrides hashCode
 boolean isGroupingUsed sample code for java.text.NumberFormat.isGroupingUsed() definition code for java.text.NumberFormat.isGroupingUsed() ()
          Returns true if grouping is used in this format.
 boolean isParseIntegerOnly sample code for java.text.NumberFormat.isParseIntegerOnly() definition code for java.text.NumberFormat.isParseIntegerOnly() ()
          Returns true if this format will parse numbers as integers only.
 Number sample code for java.lang.Number definition code for java.lang.Number parse sample code for java.text.NumberFormat.parse(java.lang.String) definition code for java.text.NumberFormat.parse(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  source)
          Parses text from the beginning of the given string to produce a number.
abstract  Number sample code for java.lang.Number definition code for java.lang.Number parse sample code for java.text.NumberFormat.parse(java.lang.String, java.text.ParsePosition) definition code for java.text.NumberFormat.parse(java.lang.String, java.text.ParsePosition) (String sample code for java.lang.String definition code for java.lang.String  source, ParsePosition sample code for java.text.ParsePosition definition code for java.text.ParsePosition  parsePosition)
          Returns a Long if possible (e.g., within the range [Long.MIN_VALUE, Long.MAX_VALUE] and with no decimals), otherwise a Double.
 Object sample code for java.lang.Object definition code for java.lang.Object parseObject sample code for java.text.NumberFormat.parseObject(java.lang.String, java.text.ParsePosition) definition code for java.text.NumberFormat.parseObject(java.lang.String, java.text.ParsePosition) (String sample code for java.lang.String definition code for java.lang.String  source, ParsePosition sample code for java.text.ParsePosition definition code for java.text.ParsePosition  pos)
          Parses text from a string to produce a Number.
 void setCurrency sample code for java.text.NumberFormat.setCurrency(java.util.Currency) definition code for java.text.NumberFormat.setCurrency(java.util.Currency) (Currency sample code for java.util.Currency definition code for java.util.Currency  currency)
          Sets the currency used by this number format when formatting currency values.
 void setGroupingUsed sample code for java.text.NumberFormat.setGroupingUsed(boolean) definition code for java.text.NumberFormat.setGroupingUsed(boolean) (boolean newValue)
          Set whether or not grouping will be used in this format.
 void setMaximumFractionDigits sample code for java.text.NumberFormat.setMaximumFractionDigits(int) definition code for java.text.NumberFormat.setMaximumFractionDigits(int) (int newValue)
          Sets the maximum number of digits allowed in the fraction portion of a number.
 void setMaximumIntegerDigits sample code for java.text.NumberFormat.setMaximumIntegerDigits(int) definition code for java.text.NumberFormat.setMaximumIntegerDigits(int) (int newValue)
          Sets the maximum number of digits allowed in the integer portion of a number.
 void setMinimumFractionDigits sample code for java.text.NumberFormat.setMinimumFractionDigits(int) definition code for java.text.NumberFormat.setMinimumFractionDigits(int) (int newValue)
          Sets the minimum number of digits allowed in the fraction portion of a number.
 void setMinimumIntegerDigits sample code for java.text.NumberFormat.setMinimumIntegerDigits(int) definition code for java.text.NumberFormat.setMinimumIntegerDigits(int) (int newValue)
          Sets the minimum number of digits allowed in the integer portion of a number.
 void setParseIntegerOnly sample code for java.text.NumberFormat.setParseIntegerOnly(boolean) definition code for java.text.NumberFormat.setParseIntegerOnly(boolean) (boolean value)
          Sets whether or not numbers should be parsed as integers only.
 
Methods inherited from class java.text.Format sample code for java.text.Format definition code for java.text.Format
format sample code for java.text.Format.format(java.lang.Object) definition code for java.text.Format.format(java.lang.Object) , formatToCharacterIterator sample code for java.text.Format.formatToCharacterIterator(java.lang.Object) definition code for java.text.Format.formatToCharacterIterator(java.lang.Object) , parseObject sample code for java.text.Format.parseObject(java.lang.String) definition code for java.text.Format.parseObject(java.lang.String)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

INTEGER_FIELD sample code for java.text.NumberFormat.INTEGER_FIELD

public static final int INTEGER_FIELD
Field constant used to construct a FieldPosition object. Signifies that the position of the integer part of a formatted number should be returned.

See Also:
FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition , Constant Field Values

FRACTION_FIELD sample code for java.text.NumberFormat.FRACTION_FIELD

public static final int FRACTION_FIELD
Field constant used to construct a FieldPosition object. Signifies that the position of the fraction part of a formatted number should be returned.

See Also:
FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition , Constant Field Values
Constructor Detail

NumberFormat sample code for java.text.NumberFormat() definition code for java.text.NumberFormat()

public NumberFormat()
Method Detail

format sample code for java.text.NumberFormat.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.NumberFormat.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)

public StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  format(Object sample code for java.lang.Object definition code for java.lang.Object  number,
                           StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  toAppendTo,
                           FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition  pos)
Formats a number and appends the resulting text to the given string buffer. The number can be of any subclass of Number sample code for java.lang.Number definition code for java.lang.Number .

This implementation extracts the number's value using Number.longValue() sample code for java.lang.Number.longValue() definition code for java.lang.Number.longValue() for all integral type values that can be converted to long without loss of information, including BigInteger values with a bit length sample code for java.math.BigInteger.bitLength() definition code for java.math.BigInteger.bitLength() of less than 64, and Number.doubleValue() sample code for java.lang.Number.doubleValue() definition code for java.lang.Number.doubleValue() for all other types. It then calls format(long,java.lang.StringBuffer,java.text.FieldPosition) sample code for java.text.NumberFormat.format(long, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.NumberFormat.format(long, java.lang.StringBuffer, java.text.FieldPosition) or format(double,java.lang.StringBuffer,java.text.FieldPosition) sample code for java.text.NumberFormat.format(double, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.NumberFormat.format(double, java.lang.StringBuffer, java.text.FieldPosition) . This may result in loss of magnitude information and precision for BigInteger and BigDecimal values.

Specified by:
format sample code for java.text.Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) in class Format sample code for java.text.Format definition code for java.text.Format
Parameters:
number - the number to format
toAppendTo - the StringBuffer to which the formatted text is to be appended
pos - On input: an alignment field, if desired. On output: the offsets of the alignment field.
Returns:
the value passed in as toAppendTo
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if number is null or not an instance of Number.
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if toAppendTo or pos is null
See Also:
FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition

parseObject sample code for java.text.NumberFormat.parseObject(java.lang.String, java.text.ParsePosition) definition code for java.text.NumberFormat.parseObject(java.lang.String, java.text.ParsePosition)

public final Object sample code for java.lang.Object definition code for java.lang.Object  parseObject(String sample code for java.lang.String definition code for java.lang.String  source,
                                ParsePosition sample code for java.text.ParsePosition definition code for java.text.ParsePosition  pos)
Parses text from a string to produce a Number.

The method attempts to parse text starting at the index given by pos. If parsing succeeds, then the index of pos is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed number is returned. The updated pos can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of pos is not changed, the error index of pos is set to the index of the character where the error occurred, and null is returned.

See the parse(String, ParsePosition) sample code for java.text.NumberFormat.parse(java.lang.String, java.text.ParsePosition) definition code for java.text.NumberFormat.parse(java.lang.String, java.text.ParsePosition) method for more information on number parsing.

Specified by:
parseObject sample code for java.text.Format.parseObject(java.lang.String, java.text.ParsePosition) definition code for java.text.Format.parseObject(java.lang.String, java.text.ParsePosition) in class Format sample code for java.text.Format definition code for java.text.Format
Parameters:
source - A String, part of which should be parsed.
pos - A ParsePosition object with index and error index information as described above.
Returns:
A Number parsed from the string. In case of error, returns null.
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if pos is null.

format sample code for java.text.NumberFormat.format(double) definition code for java.text.NumberFormat.format(double)

public final String sample code for java.lang.String definition code for java.lang.String  format(double number)
Specialization of format.

See Also:
Format.format(java.lang.Object) sample code for java.text.Format.format(java.lang.Object) definition code for java.text.Format.format(java.lang.Object)

format sample code for java.text.NumberFormat.format(long) definition code for java.text.NumberFormat.format(long)

public final String sample code for java.lang.String definition code for java.lang.String  format(long number)
Specialization of format.

See Also:
Format.format(java.lang.Object) sample code for java.text.Format.format(java.lang.Object) definition code for java.text.Format.format(java.lang.Object)

format sample code for java.text.NumberFormat.format(double, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.NumberFormat.format(double, java.lang.StringBuffer, java.text.FieldPosition)

public abstract StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  format(double number,
                                    StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  toAppendTo,
                                    FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition  pos)
Specialization of format.

See Also:
Format.format(java.lang.Object) sample code for java.text.Format.format(java.lang.Object) definition code for java.text.Format.format(java.lang.Object)

format sample code for java.text.NumberFormat.format(long, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.NumberFormat.format(long, java.lang.StringBuffer, java.text.FieldPosition)

public abstract StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  format(long number,
                                    StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  toAppendTo,
                                    FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition  pos)
Specialization of format.

See Also:
Format.format(java.lang.Object) sample code for java.text.Format.format(java.lang.Object) definition code for java.text.Format.format(java.lang.Object)

parse sample code for java.text.NumberFormat.parse(java.lang.String, java.text.ParsePosition) definition code for java.text.NumberFormat.parse(java.lang.String, java.text.ParsePosition)

public abstract Number sample code for java.lang.Number definition code for java.lang.Number  parse(String sample code for java.lang.String definition code for java.lang.String  source,
                             ParsePosition sample code for java.text.ParsePosition definition code for java.text.ParsePosition  parsePosition)
Returns a Long if possible (e.g., within the range [Long.MIN_VALUE, Long.MAX_VALUE] and with no decimals), otherwise a Double. If IntegerOnly is set, will stop at a decimal point (or equivalent; e.g., for rational numbers "1 2/3", will stop after the 1). Does not throw an exception; if no object can be parsed, index is unchanged!

See Also:
isParseIntegerOnly() sample code for java.text.NumberFormat.isParseIntegerOnly() definition code for java.text.NumberFormat.isParseIntegerOnly() , Format.parseObject(java.lang.String, java.text.ParsePosition) sample code for java.text.Format.parseObject(java.lang.String, java.text.ParsePosition) definition code for java.text.Format.parseObject(java.lang.String, java.text.ParsePosition)

parse sample code for java.text.NumberFormat.parse(java.lang.String) definition code for java.text.NumberFormat.parse(java.lang.String)

public Number sample code for java.lang.Number definition code for java.lang.Number  parse(String sample code for java.lang.String definition code for java.lang.String  source)
             throws ParseException sample code for java.text.ParseException definition code for java.text.ParseException 
Parses text from the beginning of the given string to produce a number. The method may not use the entire text of the given string.

See the parse(String, ParsePosition) sample code for java.text.NumberFormat.parse(java.lang.String, java.text.ParsePosition) definition code for java.text.NumberFormat.parse(java.lang.String, java.text.ParsePosition) method for more information on number parsing.

Parameters:
source - A String whose beginning should be parsed.
Returns:
A Number parsed from the string.
Throws:
ParseException sample code for java.text.ParseException definition code for java.text.ParseException - if the beginning of the specified string cannot be parsed.

isParseIntegerOnly sample code for java.text.NumberFormat.isParseIntegerOnly() definition code for java.text.NumberFormat.isParseIntegerOnly()

public boolean isParseIntegerOnly()
Returns true if this format will parse numbers as integers only. For example in the English locale, with ParseIntegerOnly true, the string "1234." would be parsed as the integer value 1234 and parsing would stop at the "." character. Of course, the exact format accepted by the parse operation is locale dependant and determined by sub-classes of NumberFormat.


setParseIntegerOnly sample code for java.text.NumberFormat.setParseIntegerOnly(boolean) definition code for java.text.NumberFormat.setParseIntegerOnly(boolean)

public void setParseIntegerOnly(boolean value)
Sets whether or not numbers should be parsed as integers only.

See Also:
isParseIntegerOnly() sample code for java.text.NumberFormat.isParseIntegerOnly() definition code for java.text.NumberFormat.isParseIntegerOnly()

getInstance sample code for java.text.NumberFormat.getInstance() definition code for java.text.NumberFormat.getInstance()

public static final NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getInstance()
Returns a general-purpose number format for the current default locale. This is the same as calling getNumberInstance() sample code for java.text.NumberFormat.getNumberInstance() definition code for java.text.NumberFormat.getNumberInstance() .


getInstance sample code for java.text.NumberFormat.getInstance(java.util.Locale) definition code for java.text.NumberFormat.getInstance(java.util.Locale)

public static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getInstance(Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
Returns a general-purpose number format for the specified locale. This is the same as calling getNumberInstance(inLocale) sample code for java.text.NumberFormat.getNumberInstance(java.util.Locale) definition code for java.text.NumberFormat.getNumberInstance(java.util.Locale) .


getNumberInstance sample code for java.text.NumberFormat.getNumberInstance() definition code for java.text.NumberFormat.getNumberInstance()

public static final NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getNumberInstance()
Returns a general-purpose number format for the current default locale.


getNumberInstance sample code for java.text.NumberFormat.getNumberInstance(java.util.Locale) definition code for java.text.NumberFormat.getNumberInstance(java.util.Locale)

public static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getNumberInstance(Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
Returns a general-purpose number format for the specified locale.


getIntegerInstance sample code for java.text.NumberFormat.getIntegerInstance() definition code for java.text.NumberFormat.getIntegerInstance()

public static final NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getIntegerInstance()
Returns an integer number format for the current default locale. The returned number format is configured to round floating point numbers to the nearest integer using IEEE half-even rounding (see ROUND_HALF_EVEN sample code for java.math.BigDecimal.ROUND_HALF_EVEN definition code for java.math.BigDecimal.ROUND_HALF_EVEN ) for formatting, and to parse only the integer part of an input string (see isParseIntegerOnly sample code for java.text.NumberFormat.isParseIntegerOnly() definition code for java.text.NumberFormat.isParseIntegerOnly() ).

Returns:
a number format for integer values
Since:
1.4

getIntegerInstance sample code for java.text.NumberFormat.getIntegerInstance(java.util.Locale) definition code for java.text.NumberFormat.getIntegerInstance(java.util.Locale)

public static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getIntegerInstance(Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
Returns an integer number format for the specified locale. The returned number format is configured to round floating point numbers to the nearest integer using IEEE half-even rounding (see ROUND_HALF_EVEN sample code for java.math.BigDecimal.ROUND_HALF_EVEN definition code for java.math.BigDecimal.ROUND_HALF_EVEN ) for formatting, and to parse only the integer part of an input string (see isParseIntegerOnly sample code for java.text.NumberFormat.isParseIntegerOnly() definition code for java.text.NumberFormat.isParseIntegerOnly() ).

Parameters:
inLocale - the locale for which a number format is needed
Returns:
a number format for integer values
Since:
1.4

getCurrencyInstance sample code for java.text.NumberFormat.getCurrencyInstance() definition code for java.text.NumberFormat.getCurrencyInstance()

public static final NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getCurrencyInstance()
Returns a currency format for the current default locale.


getCurrencyInstance sample code for java.text.NumberFormat.getCurrencyInstance(java.util.Locale) definition code for java.text.NumberFormat.getCurrencyInstance(java.util.Locale)

public static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getCurrencyInstance(Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
Returns a currency format for the specified locale.


getPercentInstance sample code for java.text.NumberFormat.getPercentInstance() definition code for java.text.NumberFormat.getPercentInstance()

public static final NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getPercentInstance()
Returns a percentage format for the current default locale.


getPercentInstance sample code for java.text.NumberFormat.getPercentInstance(java.util.Locale) definition code for java.text.NumberFormat.getPercentInstance(java.util.Locale)

public static NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat  getPercentInstance(Locale sample code for java.util.Locale definition code for java.util.Locale  inLocale)
Returns a percentage format for the specified locale.


getAvailableLocales sample code for java.text.NumberFormat.getAvailableLocales() definition code for java.text.NumberFormat.getAvailableLocales()

public static Locale sample code for java.util.Locale definition code for java.util.Locale [] getAvailableLocales()
Returns an array of all locales for which the get*Instance methods of this class can return localized instances. The array returned must contain at least a Locale instance equal to Locale.US sample code for java.util.Locale.US definition code for java.util.Locale.US .

Returns:
An array of locales for which localized NumberFormat instances are available.

hashCode sample code for java.text.NumberFormat.hashCode() definition code for java.text.NumberFormat.hashCode()

public int hashCode()
Overrides hashCode

Overrides:
hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

equals sample code for java.text.NumberFormat.equals(java.lang.Object) definition code for java.text.NumberFormat.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.Object  obj)
Overrides equals

Overrides:
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

clone sample code for java.text.NumberFormat.clone() definition code for java.text.NumberFormat.clone()

public Object sample code for java.lang.Object definition code for java.lang.Object  clone()
Overrides Cloneable

Overrides:
clone sample code for java.text.Format.clone() definition code for java.text.Format.clone() in class Format sample code for java.text.Format definition code for java.text.Format
Returns:
a clone of this instance.
See Also:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

isGroupingUsed sample code for java.text.NumberFormat.isGroupingUsed() definition code for java.text.NumberFormat.isGroupingUsed()

public boolean isGroupingUsed()
Returns true if grouping is used in this format. For example, in the English locale, with grouping on, the number 1234567 might be formatted as "1,234,567". The grouping separator as well as the size of each group is locale dependant and is determined by sub-classes of NumberFormat.

See Also:
setGroupingUsed(boolean) sample code for java.text.NumberFormat.setGroupingUsed(boolean) definition code for java.text.NumberFormat.setGroupingUsed(boolean)

setGroupingUsed sample code for java.text.NumberFormat.setGroupingUsed(boolean) definition code for java.text.NumberFormat.setGroupingUsed(boolean)

public void setGroupingUsed(boolean newValue)
Set whether or not grouping will be used in this format.

See Also:
isGroupingUsed() sample code for java.text.NumberFormat.isGroupingUsed() definition code for java.text.NumberFormat.isGroupingUsed()

getMaximumIntegerDigits sample code for java.text.NumberFormat.getMaximumIntegerDigits() definition code for java.text.NumberFormat.getMaximumIntegerDigits()

public int getMaximumIntegerDigits()
Returns the maximum number of digits allowed in the integer portion of a number.

See Also:
setMaximumIntegerDigits(int) sample code for java.text.NumberFormat.setMaximumIntegerDigits(int) definition code for java.text.NumberFormat.setMaximumIntegerDigits(int)

setMaximumIntegerDigits sample code for java.text.NumberFormat.setMaximumIntegerDigits(int) definition code for java.text.NumberFormat.setMaximumIntegerDigits(int)

public void setMaximumIntegerDigits(int newValue)
Sets the maximum number of digits allowed in the integer portion of a number. maximumIntegerDigits must be >= minimumIntegerDigits. If the new value for maximumIntegerDigits is less than the current value of minimumIntegerDigits, then minimumIntegerDigits will also be set to the new value.

Parameters:
newValue - the maximum number of integer digits to be shown; if less than zero, then zero is used. The concrete subclass may enforce an upper limit to this value appropriate to the numeric type being formatted.
See Also:
getMaximumIntegerDigits() sample code for java.text.NumberFormat.getMaximumIntegerDigits() definition code for java.text.NumberFormat.getMaximumIntegerDigits()

getMinimumIntegerDigits sample code for java.text.NumberFormat.getMinimumIntegerDigits() definition code for java.text.NumberFormat.getMinimumIntegerDigits()

public int getMinimumIntegerDigits()
Returns the minimum number of digits allowed in the integer portion of a number.

See Also:
setMinimumIntegerDigits(int) sample code for java.text.NumberFormat.setMinimumIntegerDigits(int) definition code for java.text.NumberFormat.setMinimumIntegerDigits(int)

setMinimumIntegerDigits sample code for java.text.NumberFormat.setMinimumIntegerDigits(int) definition code for java.text.NumberFormat.setMinimumIntegerDigits(int)

public void setMinimumIntegerDigits(int newValue)
Sets the minimum number of digits allowed in the integer portion of a number. minimumIntegerDigits must be <= maximumIntegerDigits. If the new value for minimumIntegerDigits exceeds the current value of maximumIntegerDigits, then maximumIntegerDigits will also be set to the new value

Parameters:
newValue - the minimum number of integer digits to be shown; if less than zero, then zero is used. The concrete subclass may enforce an upper limit to this value appropriate to the numeric type being formatted.
See Also:
getMinimumIntegerDigits() sample code for java.text.NumberFormat.getMinimumIntegerDigits() definition code for java.text.NumberFormat.getMinimumIntegerDigits()

getMaximumFractionDigits sample code for java.text.NumberFormat.getMaximumFractionDigits() definition code for java.text.NumberFormat.getMaximumFractionDigits()

public int getMaximumFractionDigits()
Returns the maximum number of digits allowed in the fraction portion of a number.

See Also:
setMaximumFractionDigits(int) sample code for java.text.NumberFormat.setMaximumFractionDigits(int) definition code for java.text.NumberFormat.setMaximumFractionDigits(int)

setMaximumFractionDigits sample code for java.text.NumberFormat.setMaximumFractionDigits(int) definition code for java.text.NumberFormat.setMaximumFractionDigits(int)

public void setMaximumFractionDigits(int newValue)
Sets the maximum number of digits allowed in the fraction portion of a number. maximumFractionDigits must be >= minimumFractionDigits. If the new value for maximumFractionDigits is less than the current value of minimumFractionDigits, then minimumFractionDigits will also be set to the new value.

Parameters:
newValue - the maximum number of fraction digits to be shown; if less than zero, then zero is used. The concrete subclass may enforce an upper limit to this value appropriate to the numeric type being formatted.
See Also:
getMaximumFractionDigits() sample code for java.text.NumberFormat.getMaximumFractionDigits() definition code for java.text.NumberFormat.getMaximumFractionDigits()

getMinimumFractionDigits sample code for java.text.NumberFormat.getMinimumFractionDigits() definition code for java.text.NumberFormat.getMinimumFractionDigits()

public int getMinimumFractionDigits()
Returns the minimum number of digits allowed in the fraction portion of a number.

See Also:
setMinimumFractionDigits(int) sample code for java.text.NumberFormat.setMinimumFractionDigits(int) definition code for java.text.NumberFormat.setMinimumFractionDigits(int)

setMinimumFractionDigits sample code for java.text.NumberFormat.setMinimumFractionDigits(int) definition code for java.text.NumberFormat.setMinimumFractionDigits(int)

public void setMinimumFractionDigits(int newValue)
Sets the minimum number of digits allowed in the fraction portion of a number. minimumFractionDigits must be <= maximumFractionDigits. If the new value for minimumFractionDigits exceeds the current value of maximumFractionDigits, then maximumIntegerDigits will also be set to the new value

Parameters:
newValue - the minimum number of fraction digits to be shown; if less than zero, then zero is used. The concrete subclass may enforce an upper limit to this value appropriate to the numeric type being formatted.
See Also:
getMinimumFractionDigits() sample code for java.text.NumberFormat.getMinimumFractionDigits() definition code for java.text.NumberFormat.getMinimumFractionDigits()

getCurrency sample code for java.text.NumberFormat.getCurrency() definition code for java.text.NumberFormat.getCurrency()

public Currency sample code for java.util.Currency definition code for java.util.Currency  getCurrency()
Gets the currency used by this number format when formatting currency values. The initial value is derived in a locale dependent way. The returned value may be null if no valid currency could be determined and no currency has been set using setCurrency sample code for java.text.NumberFormat.setCurrency(java.util.Currency) definition code for java.text.NumberFormat.setCurrency(java.util.Currency) .

The default implementation throws UnsupportedOperationException.

Returns:
the currency used by this number format, or null
Throws:
UnsupportedOperationException sample code for java.lang.UnsupportedOperationException definition code for java.lang.UnsupportedOperationException - if the number format class doesn't implement currency formatting
Since:
1.4

setCurrency sample code for java.text.NumberFormat.setCurrency(java.util.Currency) definition code for java.text.NumberFormat.setCurrency(java.util.Currency)

public void setCurrency(Currency sample code for java.util.Currency definition code for java.util.Currency  currency)
Sets the currency used by this number format when formatting currency values. This does not update the minimum or maximum number of fraction digits used by the number format.

The default implementation throws UnsupportedOperationException.

Parameters:
currency - the new currency to be used by this number format
Throws:
UnsupportedOperationException sample code for java.lang.UnsupportedOperationException definition code for java.lang.UnsupportedOperationException - if the number format class doesn't implement currency formatting
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if currency is null
Since:
1.4