DecimalFormatNameDecimalFormatSynopsis
DescriptionThe DecimalFormat class is a concrete subclass of NumberFormat that formats and parses numbers using a formatting pattern. Typically, you do not need to instantiate DecimalFormat yourself. Instead, the factory methods of NumberFormat return instances of DecimalFormat that are appropriate for particular locales. However, if you need a specialized number format, you can instantiate your own DecimalFormat using a pattern string. You can also modify the formatting pattern of an existing DecimalFormat object using the applyPattern() method. A pattern string has the following form:
positive-pattern[;negative-pattern] If the negative pattern is omitted, negative numbers are formatted using the positive pattern with a - character prepended to the result. Each pattern has the following form:
[prefix]integer[.fraction][suffix] The following symbols are significant in the pattern string.
Any characters other than these special characters can appear in the prefix or the suffix. A single quote can be used to escape a special character, if you need to use one of these symbols in a prefix or a suffix. For example, the pattern string for U.S. currency values is:
$#,##0.00;($#,##0.00) This indicates that a $ character is prepended to all formatted values. The grouping separator character , is inserted every three digits. Exactly two digits after the decimal place are always shown. Negative values are shown in parentheses. Thus, the value -1234.56 produces output like:
($1,234.56) Internally, the DecimalFormat class uses a DecimalFormatSymbols object to get the numerical strings that are appropriate for a particular locale. If you want to modify these strings, you can get the DecimalFormatSymbols object by calling getDecimalFormatSymbols(). Class Summary
public class java.text.DecimalFormat extends java.text.NumberFormat { // Constructors public DecimalFormat(); public DecimalFormat(String pattern); public DecimalFormat(String pattern, DecimalFormatSymbols symbols); // Instance Methods public void applyLocalizedPattern(String pattern); public void applyPattern(String pattern); public Object clone(); public boolean equals(Object obj); public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition); public StringBuffer format(long number, StringBuffer result, FieldPosition fieldPosition); public DecimalFormatSymbols getDecimalFormatSymbols(); public int getGroupingSize(); public int getMultiplier(); public String getNegativePrefix(); public String getNegativeSuffix(); public String getPositivePrefix(); public String getPositiveSuffix(); public int hashCode(); public boolean isDecimalSeparatorAlwaysShown(); public Number parse(String text, ParsePosition status); 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); public void setPositivePrefix(String newValue); public void setPositiveSuffix(String newValue); public String toLocalizedPattern(); public String toPattern(); } ConstructorsDecimalFormatpublic DecimalFormat()
public DecimalFormat(String pattern)
public DecimalFormat(String pattern, DecimalFormatSymbols symbols)
Instance MethodsapplyLocalizedPatternpublic void applyLocalizedPattern(String pattern)
applyPatternpublic void applyPattern(String pattern)
clonepublic Object clone()
equalspublic boolean equals(Object obj)
format
public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition)
public StringBuffer format(long number, StringBuffer result, FieldPosition fieldPosition)
getDecimalFormatSymbolspublic DecimalFormatSymbols getDecimalFormatSymbols()
getGroupingSizepublic int getGroupingSize()
getMultiplierpublic int getMultiplier()
getNegativePrefixpublic String getNegativePrefix()
getNegativeSuffixpublic String getNegativeSuffix()
getPositivePrefixpublic String getPositivePrefix()
getPositiveSuffixpublic String getPositiveSuffix()
hashCodepublic int hashCode()
isDecimalSeparatorAlwaysShownpublic boolean isDecimalSeparatorAlwaysShown()
parsepublic Number parse(String text, ParsePosition status)
setDecimalFormatSymbols
public void setDecimalFormatSymbols( DecimalFormatSymbols newSymbols)
setDecimalSeparatorAlwaysShownpublic void setDecimalSeparatorAlwaysShown(boolean newValue)
setGroupingSizepublic void setGroupingSize(int newValue)
setMultiplierpublic void setMultiplier(int newValue)
setNegativePrefixpublic void setNegativePrefix(String newValue)
setNegativeSuffixpublic void setNegativeSuffix(String newValue)
setPositivePrefixpublic void setPositivePrefix(String newValue)
setPositiveSuffixpublic void setPositiveSuffix(String newValue)
toLocalizedPatternpublic String toLocalizedPattern()
toPatternpublic String toPattern()
Inherited Methods
See AlsoDecimalFormatSymbols, FieldPosition, Number, NumberFormat, ParsePosition, String, StringBuffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|