java.text.DecimalFormat (JDK 1.1)
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 may 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 be used to change this pattern. A pattern consists of a string of characters from the following table. For example: "$#,##0.00;($#,##0.00)".
| Character | Meaning |
|---|---|
| # | digit; zeros show as absent |
| digit; zeros show as 0 | |
| The locale-specific decimal separator | |
| The locale-specific grouping separator | |
| - | The locale-specific negative prefix |
| % | Show value as a percentage |
| ; | Separates positive number format (on left) from optional negative number format (on right) |
| ' | Quote a reserved character, so it appears literally in the output |
| other | Appears literally in output |
A DecimalFormatSymbols object may be optionally specified when creating a DecimalFormat object. If one is not specified, a DecimalFormatSymbols object suitable for the default locale is used.
public classDecimalFormatextends NumberFormat { //Public ConstructorspublicDecimalFormat(); publicDecimalFormat(Stringpattern); publicDecimalFormat(Stringpattern, DecimalFormatSymbolssymbols); //Public Instance Methodspublic voidapplyLocalizedPattern(Stringpattern); public voidapplyPattern(Stringpattern); public Objectclone(); //Overrides NumberFormatpublic booleanequals(Objectobj); //Overrides NumberFormatpublic StringBufferformat(doublenumber, StringBufferresult, FieldPositionfieldPosition); //Defines NumberFormatpublic StringBufferformat(longnumber, StringBufferresult, FieldPositionfieldPosition); //Defines NumberFormatpublic DecimalFormatSymbolsgetDecimalFormatSymbols(); public intgetGroupingSize(); public intgetMultiplier(); public StringgetNegativePrefix(); public StringgetNegativeSuffix(); public StringgetPositivePrefix(); public StringgetPositiveSuffix(); public inthashCode(); //Overrides NumberFormatpublic booleanisDecimalSeparatorAlwaysShown(); public Numberparse(Stringtext, ParsePositionstatus); //Defines NumberFormatpublic voidsetDecimalFormatSymbols(DecimalFormatSymbolsnewSymbols); public voidsetDecimalSeparatorAlwaysShown(booleannewValue); public voidsetGroupingSize(intnewValue); public voidsetMultiplier(intnewValue); public voidsetNegativePrefix(StringnewValue); public voidsetNegativeSuffix(StringnewValue); public voidsetPositivePrefix(StringnewValue); public voidsetPositiveSuffix(StringnewValue); public StringtoLocalizedPattern(); public StringtoPattern(); }
Hierarchy:
Object->Format(Serializable, Cloneable)->NumberFormat(Cloneable)->DecimalFormat