java.text
Class DecimalFormat

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 sample code for java.text.NumberFormat definition code for java.text.NumberFormat 
          extended by java.text.DecimalFormat
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

public class DecimalFormat
extends NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits. It also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized.

To obtain a NumberFormat for a specific locale, including the default locale, call one of NumberFormat's factory methods, such as getInstance(). In general, do not call the DecimalFormat constructors directly, since the NumberFormat factory methods may return subclasses other than DecimalFormat. If you need to customize the format object, do something like this:

 NumberFormat f = NumberFormat.getInstance(loc);
 if (f instanceof DecimalFormat) {
     ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true);
 }
 

A DecimalFormat comprises a pattern and a set of symbols. The pattern may be set directly using applyPattern(), or indirectly using the API methods. The symbols are stored in a DecimalFormatSymbols object. When using the NumberFormat factory methods, the pattern and symbols are read from localized ResourceBundles.

Patterns

DecimalFormat patterns have the following syntax:
 Pattern:
         PositivePattern
         PositivePattern ; NegativePattern
 PositivePattern:
         Prefixopt Number Suffixopt
 NegativePattern:
         Prefixopt Number Suffixopt
 Prefix:
         any Unicode characters except \uFFFE, \uFFFF, and special characters
 Suffix:
         any Unicode characters except \uFFFE, \uFFFF, and special characters
 Number:
         Integer Exponentopt
         Integer . Fraction Exponentopt
 Integer:
         MinimumInteger
         #
         # Integer
         # , Integer
 MinimumInteger:
         0
         0 MinimumInteger
         0 , MinimumInteger
 Fraction:
         MinimumFractionopt OptionalFractionopt
 MinimumFraction:
         0 MinimumFractionopt
 OptionalFraction:
         # OptionalFractionopt
 Exponent:
         E MinimumExponent
 MinimumExponent:
         0 MinimumExponentopt
 

A DecimalFormat pattern contains a positive and negative subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a prefix, numeric part, and suffix. The negative subpattern is optional; if absent, then the positive subpattern prefixed with the localized minus sign ('-' in most locales) is used as the negative subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are all the same as the positive pattern. That means that "#,##0.0#;(#)" produces precisely the same behavior as "#,##0.0#;(#,##0.0#)".

The prefixes, suffixes, and various symbols used for infinity, digits, thousands separators, decimal separators, etc. may be set to arbitrary values, and they will appear properly during formatting. However, care must be taken that the symbols and strings do not conflict, or parsing will be unreliable. For example, either the positive and negative prefixes or the suffixes must be distinct for DecimalFormat.parse() to be able to distinguish positive from negative values. (If they are identical, then DecimalFormat will behave as if no negative subpattern was specified.) Another example is that the decimal separator and thousands separator should be distinct characters, or parsing will be impossible.

The grouping separator is commonly used for thousands, but in some countries it separates ten-thousands. The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".

Special Pattern Characters

Many characters in a pattern are taken literally; they are matched during parsing and output unchanged during formatting. Special characters, on the other hand, stand for other characters, strings, or classes of characters. They must be quoted, unless noted otherwise, if they are to appear in the prefix or suffix as literals.

The characters listed here are used in non-localized patterns. Localized patterns use the corresponding characters taken from this formatter's DecimalFormatSymbols object instead, and these characters lose their special status. Two exceptions are the currency sign and quote, which are not localized.

Symbol Location Localized? Meaning
0 Number Yes Digit
# Number Yes Digit, zero shows as absent
. Number Yes Decimal separator or monetary decimal separator
- Number Yes Minus sign
, Number Yes Grouping separator
E Number Yes Separates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix.
; Subpattern boundary Yes Separates positive and negative subpatterns
% Prefix or suffix Yes Multiply by 100 and show as percentage
\u2030 Prefix or suffix Yes Multiply by 1000 and show as per mille value
¤ (\u00A4) Prefix or suffix No Currency sign, replaced by currency symbol. If doubled, replaced by international currency symbol. If present in a pattern, the monetary decimal separator is used instead of the decimal separator.
' Prefix or suffix No Used to quote special characters in a prefix or suffix, for example, "'#'#" formats 123 to "#123". To create a single quote itself, use two in a row: "# o''clock".

Scientific Notation

Numbers in scientific notation are expressed as the product of a mantissa and a power of ten, for example, 1234 can be expressed as 1.234 x 10^3. The mantissa is often in the range 1.0 <= x < 10.0, but it need not be. DecimalFormat can be instructed to format and parse scientific notation only via a pattern; there is currently no factory method that creates a scientific notation format. In a pattern, the exponent character immediately followed by one or more digit characters indicates scientific notation. Example: "0.###E0" formats the number 1234 as "1.234E3".

Rounding

DecimalFormat uses 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.

Digits

For formatting, DecimalFormat uses the ten consecutive characters starting with the localized zero digit defined in the DecimalFormatSymbols object as digits. For parsing, these digits as well as all Unicode decimal digits, as defined by Character.digit sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , are recognized.

Special Values

NaN is formatted as a single character, typically \uFFFD. This character is determined by the DecimalFormatSymbols object. This is the only value for which the prefixes and suffixes are not used.

Infinity is formatted as a single character, typically \u221E, with the positive or negative prefixes and suffixes applied. The infinity character is determined by the DecimalFormatSymbols object.

Negative zero ("-0") parses to

Synchronization

Decimal 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.

Example

 // Print out a number using the localized number, integer, currency,
 // and percent format for each locale
 Locale[] locales = NumberFormat.getAvailableLocales();
 double myNumber = -1234.56;
 NumberFormat form;
 for (int j=0; j<4; ++j) {
     System.out.println("FORMAT");
     for (int i = 0; i < locales.length; ++i) {
         if (locales[i].getCountry().length() == 0) {
            continue; // Skip language-only locales
         }
         System.out.print(locales[i].getDisplayName());
         switch (j) {
         case 0:
             form = NumberFormat.getInstance(locales[i]); break;
         case 1:
             form = NumberFormat.getIntegerInstance(locales[i]); break;
         case 2:
             form = NumberFormat.getCurrencyInstance(locales[i]); break;
         default:
             form = NumberFormat.getPercentInstance(locales[i]); break;
         }
         if (form instanceof DecimalFormat) {
             System.out.print(": " + ((DecimalFormat) form).toPattern());
         }
         System.out.print(" -> " + form.format(myNumber));
         try {
             System.out.println(" -> " + form.parse(form.format(myNumber)));
         } catch (ParseException e) {}
     }
 }
 

See Also:
Java Tutorial, NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat , DecimalFormatSymbols sample code for java.text.DecimalFormatSymbols definition code for java.text.DecimalFormatSymbols , ParsePosition sample code for java.text.ParsePosition definition code for java.text.ParsePosition , Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat
NumberFormat.Field sample code for java.text.NumberFormat.Field definition code for java.text.NumberFormat.Field
 
Field Summary
 
Fields inherited from class java.text.NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat
FRACTION_FIELD sample code for java.text.NumberFormat.FRACTION_FIELD definition code for java.text.NumberFormat.FRACTION_FIELD , INTEGER_FIELD sample code for java.text.NumberFormat.INTEGER_FIELD definition code for java.text.NumberFormat.INTEGER_FIELD
 
Constructor Summary
DecimalFormat sample code for java.text.DecimalFormat.DecimalFormat() definition code for java.text.DecimalFormat.DecimalFormat() ()
          Creates a DecimalFormat using the default pattern and symbols for the default locale.
DecimalFormat sample code for java.text.DecimalFormat.DecimalFormat(java.lang.String) definition code for java.text.DecimalFormat.DecimalFormat(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  pattern)
          Creates a DecimalFormat using the given pattern and the symbols for the default locale.
DecimalFormat sample code for java.text.DecimalFormat.DecimalFormat(java.lang.String, java.text.DecimalFormatSymbols) definition code for java.text.DecimalFormat.DecimalFormat(java.lang.String, java.text.DecimalFormatSymbols) (String sample code for java.lang.String definition code for java.lang.String  pattern, DecimalFormatSymbols sample code for java.text.DecimalFormatSymbols definition code for java.text.DecimalFormatSymbols  symbols)
          Creates a DecimalFormat using the given pattern and symbols.
 
Method Summary
 void applyLocalizedPattern sample code for java.text.DecimalFormat.applyLocalizedPattern(java.lang.String) definition code for java.text.DecimalFormat.applyLocalizedPattern(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  pattern)
          Apply the given pattern to this Format object.
 void applyPattern sample code for java.text.DecimalFormat.applyPattern(java.lang.String) definition code for java.text.DecimalFormat.applyPattern(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  pattern)
          Apply the given pattern to this Format object.
 Object sample code for java.lang.Object definition code for java.lang.Object clone sample code for java.text.DecimalFormat.clone() definition code for java.text.DecimalFormat.clone() ()
          Standard override; no change in semantics.
 boolean equals sample code for java.text.DecimalFormat.equals(java.lang.Object) definition code for java.text.DecimalFormat.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Overrides equals
 StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer format sample code for java.text.DecimalFormat.format(double, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.DecimalFormat.format(double, java.lang.StringBuffer, java.text.FieldPosition) (double number, StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  result, FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition  fieldPosition)
          Formats a double to produce a string.
 StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer format sample code for java.text.DecimalFormat.format(long, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.DecimalFormat.format(long, java.lang.StringBuffer, java.text.FieldPosition) (long number, StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer  result, FieldPosition sample code for java.text.FieldPosition definition code for java.text.FieldPosition  fieldPosition)
          Format a long to produce a string.
 StringBuffer sample code for java.lang.StringBuffer definition code for java.lang.StringBuffer format sample code for java.text.DecimalFormat.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) definition code for java.text.DecimalFormat.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.
 AttributedCharacterIterator sample code for java.text.AttributedCharacterIterator definition code for java.text.AttributedCharacterIterator formatToCharacterIterator sample code for java.text.DecimalFormat.formatToCharacterIterator(java.lang.Object) definition code for java.text.DecimalFormat.formatToCharacterIterator(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Formats an Object producing an AttributedCharacterIterator.
 Currency sample code for java.util.Currency definition code for java.util.Currency getCurrency sample code for java.text.DecimalFormat.getCurrency() definition code for java.text.DecimalFormat.getCurrency() ()
          Gets the currency used by this decimal format when formatting currency values.
 DecimalFormatSymbols sample code for java.text.DecimalFormatSymbols definition code for java.text.DecimalFormatSymbols getDecimalFormatSymbols sample code for java.text.DecimalFormat.getDecimalFormatSymbols() definition code for java.text.DecimalFormat.getDecimalFormatSymbols() ()
          Returns the decimal format symbols, which is generally not changed by the programmer or user.
 int getGroupingSize sample code for java.text.DecimalFormat.getGroupingSize() definition code for java.text.DecimalFormat.getGroupingSize() ()
          Return the grouping size.
 int getMaximumFractionDigits sample code for java.text.DecimalFormat.getMaximumFractionDigits() definition code for java.text.DecimalFormat.getMaximumFractionDigits() ()
          Gets the maximum number of digits allowed in the fraction portion of a number.
 int getMaximumIntegerDigits sample code for java.text.DecimalFormat.getMaximumIntegerDigits() definition code for java.text.DecimalFormat.getMaximumIntegerDigits() ()
          Gets the maximum number of digits allowed in the integer portion of a number.
 int getMinimumFractionDigits sample code for java.text.DecimalFormat.getMinimumFractionDigits() definition code for java.text.DecimalFormat.getMinimumFractionDigits() ()
          Gets the minimum number of digits allowed in the fraction portion of a number.
 int getMinimumIntegerDigits sample code for java.text.DecimalFormat.getMinimumIntegerDigits() definition code for java.text.DecimalFormat.getMinimumIntegerDigits() ()
          Gets the minimum number of digits allowed in the integer portion of a number.
 int getMultiplier sample code for java.text.DecimalFormat.getMultiplier() definition code for java.text.DecimalFormat.getMultiplier() ()
          Gets the multiplier for use in percent, per mille, and similar formats.
 String sample code for java.lang.String definition code for java.lang.String getNegativePrefix sample code for java.text.DecimalFormat.getNegativePrefix() definition code for java.text.DecimalFormat.getNegativePrefix() ()
          Get the negative prefix.
 String sample code for java.lang.String definition code for java.lang.String getNegativeSuffix sample code for java.text.DecimalFormat.getNegativeSuffix() definition code for java.text.DecimalFormat.getNegativeSuffix() ()
          Get the negative suffix.
 String sample code for java.lang.String definition code for java.lang.String getPositivePrefix sample code for java.text.DecimalFormat.getPositivePrefix() definition code for java.text.DecimalFormat.getPositivePrefix() ()
          Get the positive prefix.
 String sample code for java.lang.String definition code for java.lang.String getPositiveSuffix sample code for java.text.DecimalFormat.getPositiveSuffix() definition code for java.text.DecimalFormat.getPositiveSuffix() ()
          Get the positive suffix.
 int hashCode sample code for java.text.DecimalFormat.hashCode() definition code for java.text.DecimalFormat.hashCode() ()
          Overrides hashCode
 boolean isDecimalSeparatorAlwaysShown sample code for java.text.DecimalFormat.isDecimalSeparatorAlwaysShown() definition code for java.text.DecimalFormat.isDecimalSeparatorAlwaysShown() ()
          Allows you to get the behavior of the decimal separator with integers.
 boolean isParseBigDecimal sample code for java.text.DecimalFormat.isParseBigDecimal() definition code for java.text.DecimalFormat.isParseBigDecimal() ()
          Returns whether the parse(java.lang.String, java.text.ParsePosition) sample code for java.text.DecimalFormat.parse(java.lang.String, java.text.ParsePosition) definition code for java.text.DecimalFormat.parse(java.lang.String, java.text.ParsePosition) method returns BigDecimal.
 Number sample code for java.lang.Number definition code for java.lang.Number parse sample code for java.text.DecimalFormat.parse(java.lang.String, java.text.ParsePosition) definition code for java.text.DecimalFormat.parse(java.lang.String, java.text.ParsePosition) (String sample code for java.lang.String definition code for java.lang.String  text, 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.DecimalFormat.setCurrency(java.util.Currency) definition code for java.text.DecimalFormat.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 setDecimalFormatSymbols sample code for java.text.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols) definition code for java.text.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols) (DecimalFormatSymbols sample code for java.text.DecimalFormatSymbols definition code for java.text.DecimalFormatSymbols  newSymbols)
          Sets the decimal format symbols, which is generally not changed by the programmer or user.
 void setDecimalSeparatorAlwaysShown sample code for java.text.DecimalFormat.setDecimalSeparatorAlwaysShown(boolean) definition code for java.text.DecimalFormat.setDecimalSeparatorAlwaysShown(boolean) (boolean newValue)
          Allows you to set the behavior of the decimal separator with integers.
 void setGroupingSize sample code for java.text.DecimalFormat.setGroupingSize(int) definition code for java.text.DecimalFormat.setGroupingSize(int) (int newValue)
          Set the grouping size.
 void setMaximumFractionDigits sample code for java.text.DecimalFormat.setMaximumFractionDigits(int) definition code for java.text.DecimalFormat.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.DecimalFormat.setMaximumIntegerDigits(int) definition code for java.text.DecimalFormat.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.DecimalFormat.setMinimumFractionDigits(int) definition code for java.text.DecimalFormat.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.DecimalFormat.setMinimumIntegerDigits(int) definition code for java.text.DecimalFormat.setMinimumIntegerDigits(int) (int newValue)
          Sets the minimum number of digits allowed in the integer portion of a number.
 void setMultiplier sample code for java.text.DecimalFormat.setMultiplier(int) definition code for java.text.DecimalFormat.setMultiplier(int) (int newValue)
          Sets the multiplier for use in percent, per mille, and similar formats.
 void setNegativePrefix sample code for java.text.DecimalFormat.setNegativePrefix(java.lang.String) definition code for java.text.DecimalFormat.setNegativePrefix(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  newValue)
          Set the negative prefix.
 void setNegativeSuffix sample code for java.text.DecimalFormat.setNegativeSuffix(java.lang.String) definition code for java.text.DecimalFormat.setNegativeSuffix(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  newValue)
          Set the negative suffix.
 void setParseBigDecimal sample code for java.text.DecimalFormat.setParseBigDecimal(boolean) definition code for java.text.DecimalFormat.setParseBigDecimal(boolean) (boolean newValue)
          Sets whether the parse(java.lang.String, java.text.ParsePosition) sample code for java.text.DecimalFormat.parse(java.lang.String, java.text.ParsePosition) definition code for java.text.DecimalFormat.parse(java.lang.String, java.text.ParsePosition) method returns BigDecimal.
 void setPositivePrefix sample code for java.text.DecimalFormat.setPositivePrefix(java.lang.String) definition code for java.text.DecimalFormat.setPositivePrefix(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  newValue)
          Set the positive prefix.
 void setPositiveSuffix sample code for java.text.DecimalFormat.setPositiveSuffix(java.lang.String) definition code for java.text.DecimalFormat.setPositiveSuffix(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  newValue)
          Set the positive suffix.
 String sample code for java.lang.String definition code for java.lang.String toLocalizedPattern sample code for java.text.DecimalFormat.toLocalizedPattern() definition code for java.text.DecimalFormat.toLocalizedPattern() ()
          Synthesizes a localized pattern string that represents the current state of this Format object.
 String sample code for java.lang.String definition code for java.lang.String toPattern sample code for java.text.DecimalFormat.toPattern() definition code for java.text.DecimalFormat.toPattern() ()
          Synthesizes a pattern string that represents the current state of this Format object.
 
Methods inherited from class java.text.NumberFormat sample code for java.text.NumberFormat definition code for java.text.NumberFormat
format sample code for java.text.NumberFormat.format(double) definition code for java.text.NumberFormat.format(double) , format sample code for java.text.NumberFormat.format(long) definition code for java.text.NumberFormat.format(long) , getAvailableLocales sample code for java.text.NumberFormat.getAvailableLocales() definition code for java.text.NumberFormat.getAvailableLocales() , getCurrencyInstance sample code for java.text.NumberFormat.getCurrencyInstance() definition code for java.text.NumberFormat.getCurrencyInstance() , getCurrencyInstance sample code for java.text.NumberFormat.getCurrencyInstance(java.util.Locale) definition code for java.text.NumberFormat.getCurrencyInstance(java.util.Locale) , getInstance sample code for java.text.NumberFormat.getInstance() definition code for java.text.NumberFormat.getInstance() , getInstance sample code for java.text.NumberFormat.getInstance(java.util.Locale) definition code for java.text.NumberFormat.getInstance(java.util.Locale) , getIntegerInstance sample code for java.text.NumberFormat.getIntegerInstance() definition code for java.text.NumberFormat.getIntegerInstance() , getIntegerInstance sample code for java.text.NumberFormat.getIntegerInstance(java.util.Locale) definition code for java.text.NumberFormat.getIntegerInstance(java.util.Locale) , getNumberInstance sample code for java.text.NumberFormat.getNumberInstance() definition code for java.text.NumberFormat.getNumberInstance() , getNumberInstance sample code for java.text.NumberFormat.getNumberInstance(java.util.Locale) definition code for java.text.NumberFormat.getNumberInstance(java.util.Locale) , getPercentInstance sample code for java.text.NumberFormat.getPercentInstance() definition code for java.text.NumberFormat.getPercentInstance() , getPercentInstance sample code for java.text.NumberFormat.getPercentInstance(java.util.Locale) definition code for java.text.NumberFormat.getPercentInstance(java.util.Locale) , isGroupingUsed sample code for java.text.NumberFormat.isGroupingUsed() definition code for java.text.NumberFormat.isGroupingUsed() , isParseIntegerOnly sample code for java.text.NumberFormat.isParseIntegerOnly() definition code for java.text.NumberFormat.isParseIntegerOnly() , parse sample code for java.text.NumberFormat.parse(java.lang.String) definition code for java.text.NumberFormat.parse(java.lang.String) , 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) , setGroupingUsed sample code for java.text.NumberFormat.setGroupingUsed(boolean) definition code for java.text.NumberFormat.setGroupingUsed(boolean) , setParseIntegerOnly sample code for java.text.NumberFormat.setParseIntegerOnly(boolean) definition code for java.text.NumberFormat.setParseIntegerOnly(boolean)
 
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) , 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)
 

Constructor Detail

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

public DecimalFormat()
Creates a DecimalFormat using the default pattern and symbols for the default locale. This is a convenient way to obtain a DecimalFormat when internationalization is not the main concern.

To obtain standard formats for a given locale, use the factory methods on NumberFormat such as getNumberInstance. These factories will return the most appropriate sub-class of NumberFormat for a given locale.

See Also:
NumberFormat.getInstance() sample code for java.text.NumberFormat.getInstance() definition code for java.text.NumberFormat.getInstance() , NumberFormat.getNumberInstance() sample code for java.text.NumberFormat.getNumberInstance() definition code for java.text.NumberFormat.getNumberInstance() , NumberFormat.getCurrencyInstance() sample code for java.text.NumberFormat.getCurrencyInstance() definition code for java.text.NumberFormat.getCurrencyInstance() , NumberFormat.getPercentInstance() sample code for java.text.NumberFormat.getPercentInstance() definition code for java.text.NumberFormat.getPercentInstance()

DecimalFormat sample code for java.text.DecimalFormat(java.lang.String) definition code for java.text.DecimalFormat(java.lang.String)

public DecimalFormat(String sample code for java.lang.String definition code for java.lang.String  pattern)
Creates a DecimalFormat using the given pattern and the symbols for the default locale. This is a convenient way to obtain a DecimalFormat when internationalization is not the main concern.

To obtain standard formats for a given locale, use the factory methods on NumberFormat such as getNumberInstance. These factories will return the most appropriate sub-class of NumberFormat for a given locale.

Parameters:
pattern - A non-localized pattern string.
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if pattern is null
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the given pattern is invalid.
See Also:
NumberFormat.getInstance() sample code for java.text.NumberFormat.getInstance() definition code for java.text.NumberFormat.getInstance() , NumberFormat.getNumberInstance() sample code for java.text.NumberFormat.getNumberInstance() definition code for java.text.NumberFormat.getNumberInstance() , NumberFormat.getCurrencyInstance() sample code for java.text.NumberFormat.getCurrencyInstance() definition code for java.text.NumberFormat.getCurrencyInstance() , NumberFormat.getPercentInstance() sample code for java.text.NumberFormat.getPercentInstance() definition code for java.text.NumberFormat.getPercentInstance()

DecimalFormat