Java 1.1 | cloneable serializable |
This is the concrete Format class used by NumberFormat for all locales that use base 10 numbers. Most applications do not need to use this class directly; they can use the static methods of NumberFormat to obtain a default NumberFormat object for a desired locale and then perform minor locale-independent customizations on that object.Applications that require highly customized number formatting and parsing may create custom DecimalFormat objects by passing a suitable pattern to the DecimalFormat( ) constructor method. The applyPattern( ) method can change this pattern. A pattern consists of a string of characters from the table below. For example:"$#,##0.00;($#,##0.00)" Character | Meaning |
---|
# | A digit; zeros show as absent. | 0 | A digit; zeros show as 0. | . | The locale-specific decimal separator. | , | The locale-specific grouping separator (comma). | - | The locale-specific negative prefix. | % | Shows value as a percentage. | ; | Separates positive number format (on left) from optiona negative number format (on right). | ' | Quotes a reserved character, so it appears literally in the output (apostrophe). | other | Appears literally in output. | A DecimalFormatSymbols object can be specified optionally when creating a DecimalFormat object. If one is not specified, a DecimalFormatSymbols object suitable for the default locale is used.In Java 5.0, DecimalFormat can return java.math.BigDecimal values from its parse( ) method. Call setParseBigDecimal( ) to enable this feature. This is useful when working with very large numbers, very precise numbers, or financial applications that use BigDecimal to avoid rounding errors.
Figure 15-9. java.text.DecimalFormat
public class DecimalFormat extends NumberFormat { // Public Constructors public DecimalFormat ( ); public DecimalFormat (String pattern ); public DecimalFormat (String pattern , DecimalFormatSymbols symbols ); // Public Instance Methods public void applyLocalizedPattern (String pattern ); public void applyPattern (String pattern ); public DecimalFormatSymbols getDecimalFormatSymbols ( ); public int getGroupingSize ( ); default:3 public int getMultiplier ( ); default:1 public String getNegativePrefix ( ); default:"-" public String getNegativeSuffix ( ); default:" public String getPositivePrefix ( ); default:" public String getPositiveSuffix ( ); default:" public boolean isDecimalSeparatorAlwaysShown ( ); default:false 5.0 public boolean isParseBigDecimal ( ); default:false public void setDecimalFormatSymbols (DecimalFormatSymbols newSymbols ); public void setDecimalSeparatorAlwaysShown (boolean newValue ); public void setGroupingSize (int newValue ); public void setMultiplier (int newValue ); public void setNegativePrefix (String newValue ); public void setNegativeSuffix (String newValue ); 5.0 public void setParseBigDecimal (boolean newValue ); public void setPositivePrefix (String newValue ); public void setPositiveSuffix (String newValue ); public String toLocalizedPattern ( ); public String toPattern ( ); // Public Methods Overriding NumberFormat public Object clone ( ); public boolean equals (Object obj ); 5.0 public final StringBuffer format (Object number , StringBuffer toAppendTo , FieldPosition pos ); public StringBuffer format (double number , StringBuffer result , FieldPosition fieldPosition ); public StringBuffer format (long number , StringBuffer result , FieldPosition fieldPosition ); 1.4 public java.util.Currency getCurrency ( ); 5.0 public int getMaximumFractionDigits ( ); default:3 5.0 public int getMaximumIntegerDigits ( ); default:2147483647 5.0 public int getMinimumFractionDigits ( ); default:0 5.0 public int getMinimumIntegerDigits ( ); default:1 public int hashCode ( ); public Number parse (String text , ParsePosition pos ); 1.4 public void setCurrency (java.util.Currency currency ); 1.2 public void setMaximumFractionDigits (int newValue ); 1.2 public void setMaximumIntegerDigits (int newValue ); 1.2 public void setMinimumFractionDigits (int newValue ); 1.2 public void setMinimumIntegerDigits (int newValue ); // Public Methods Overriding Format 1.4 public AttributedCharacterIterator formatToCharacterIterator (Object obj ); }
|