|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.text.Format
java.text.NumberFormat
java.text.DecimalFormat
public class DecimalFormat
This class is a concrete implementation of NumberFormat used to format
decimal numbers. The class can format numbers given a specific locale.
Generally, to get an instance of DecimalFormat you should call the factory
methods in the NumberFormat base class.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.text.NumberFormat |
|---|
NumberFormat.Field |
| Field Summary |
|---|
| Fields inherited from class java.text.NumberFormat |
|---|
FRACTION_FIELD, INTEGER_FIELD |
| Constructor Summary | |
|---|---|
DecimalFormat()
Constructs a DecimalFormat which uses the default
pattern and symbols. |
|
DecimalFormat(String pattern)
Constructs a DecimalFormat which uses the given
pattern and the default symbols for formatting and parsing. |
|
DecimalFormat(String pattern,
DecimalFormatSymbols symbols)
Constructs a DecimalFormat using the given pattern
and formatting symbols. |
|
| Method Summary | |
|---|---|
void |
applyLocalizedPattern(String pattern)
Apply the given localized patern to the current DecimalFormat object. |
void |
applyPattern(String pattern)
Apply the given localized pattern to the current DecimalFormat object. |
Object |
clone()
Creates a copy of this object. |
boolean |
equals(Object obj)
Tests this instance for equality with an arbitrary object. |
StringBuffer |
format(double number,
StringBuffer dest,
FieldPosition fieldPos)
Produce a formatted String representation of this double. |
StringBuffer |
format(long number,
StringBuffer dest,
FieldPosition fieldPos)
Produce a formatted String representation of this long. |
StringBuffer |
format(Object obj,
StringBuffer sbuf,
FieldPosition pos)
Produce a formatted String representation of this object. |
AttributedCharacterIterator |
formatToCharacterIterator(Object value)
Return an AttributedCharacterIterator as a result of
the formatting of the passed Object. |
Currency |
getCurrency()
Returns the currency corresponding to the currency symbol stored in the instance of DecimalFormatSymbols used by this
DecimalFormat. |
DecimalFormatSymbols |
getDecimalFormatSymbols()
Returns a copy of the symbols used by this instance. |
int |
getGroupingSize()
Gets the interval used between a grouping separator and the next. |
int |
getMultiplier()
Gets the multiplier used in percent and similar formats. |
String |
getNegativePrefix()
Gets the negative prefix. |
String |
getNegativeSuffix()
Gets the negative suffix. |
String |
getPositivePrefix()
Gets the positive prefix. |
String |
getPositiveSuffix()
Gets the positive suffix. |
int |
hashCode()
Returns a hash code for this object. |
boolean |
isDecimalSeparatorAlwaysShown()
|
boolean |
isParseBigDecimal()
Returns true if
parse(java.lang.String, java.text.ParsePosition) returns
a BigDecimal, false otherwise. |
Number |
parse(String str,
ParsePosition pos)
This method parses the specified string into a Number. |
void |
setCurrency(Currency currency)
Sets the Currency on the
DecimalFormatSymbols used, which also sets the
currency symbols on those symbols. |
void |
setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
Sets the symbols used by this instance. |
void |
setDecimalSeparatorAlwaysShown(boolean newValue)
Define if the decimal separator should be always visible or only visible when needed. |
void |
setGroupingSize(int groupSize)
Sets the number of digits used to group portions of the integer part of the number. |
void |
setMaximumFractionDigits(int newValue)
Sets the maximum number of digits allowed in the fraction portion of a number to the specified value. |
void |
setMaximumIntegerDigits(int newValue)
Sets the maximum number of digits allowed in the integer portion of a number to the specified value. |
void |
setMinimumFractionDigits(int newValue)
Sets the minimum number of digits allowed in the fraction portion of a number to the specified value. |
void |
setMinimumIntegerDigits(int newValue)
Sets the minimum number of digits allowed in the integer portion of a number to the specified value. |
void |
setMultiplier(int newValue)
Sets the multiplier for use in percent and similar formats. |
void |
setNegativePrefix(String newValue)
Sets the negative prefix. |
void |
setNegativeSuffix(String newValue)
Sets the negative suffix. |
void |
setParseBigDecimal(boolean newValue)
Define if parse(java.lang.String, java.text.ParsePosition)
should return a BigDecimal or not. |
void |
setPositivePrefix(String newValue)
Sets the positive prefix. |
void |
setPositiveSuffix(String newValue)
Sets the new positive suffix. |
String |
toLocalizedPattern()
This method returns a string with the formatting pattern being used by this object. |
String |
toPattern()
This method returns a string with the formatting pattern being used by this object. |
| Methods inherited from class java.text.Format |
|---|
format, parseObject |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DecimalFormat()
DecimalFormat which uses the default
pattern and symbols.
public DecimalFormat(String pattern)
DecimalFormat which uses the given
pattern and the default symbols for formatting and parsing.
pattern - the non-localized pattern to use.
NullPointerException - if any argument is null.
IllegalArgumentException - if the pattern is invalid.
public DecimalFormat(String pattern,
DecimalFormatSymbols symbols)
DecimalFormat using the given pattern
and formatting symbols. This construction method is used to give
complete control over the formatting process.
pattern - the non-localized pattern to use.symbols - the set of symbols used for parsing and formatting.
NullPointerException - if any argument is null.
IllegalArgumentException - if the pattern is invalid.| Method Detail |
|---|
public void applyLocalizedPattern(String pattern)
pattern - The localized pattern to apply.
IllegalArgumentException - if the given pattern is invalid.
NullPointerException - if the input pattern is null.public void applyPattern(String pattern)
pattern - The localized pattern to apply.
IllegalArgumentException - if the given pattern is invalid.
NullPointerException - if the input pattern is null.public Object clone()
Format
clone in class FormatObject.Cloneablepublic boolean equals(Object obj)
true if:
obj is not null;obj is an instance of DecimalFormat;obj have the same attributes;
equals in class NumberFormatobj - the object (null permitted).
Object.hashCode()public int hashCode()
hashCode in class NumberFormatObject.equals(Object),
System.identityHashCode(Object)
public final StringBuffer format(Object obj,
StringBuffer sbuf,
FieldPosition pos)
String representation of this object.
The passed object must be of type number.
format in class NumberFormatobj - The Number to format.sbuf - The destination String; text will be appended to this String.pos - If used on input can be used to define an alignment
field. If used on output defines the offsets of the alignment field.
public StringBuffer format(double number,
StringBuffer dest,
FieldPosition fieldPos)
String representation of this double.
format in class NumberFormatnumber - The double to format.dest - The destination String; text will be appended to this String.fieldPos - If used on input can be used to define an alignment
field. If used on output defines the offsets of the alignment field.
NullPointerException - if dest or fieldPos are null
public StringBuffer format(long number,
StringBuffer dest,
FieldPosition fieldPos)
String representation of this long.
format in class NumberFormatnumber - The long to format.dest - The destination String; text will be appended to this String.fieldPos - If used on input can be used to define an alignment
field. If used on output defines the offsets of the alignment field.
public AttributedCharacterIterator formatToCharacterIterator(Object value)
AttributedCharacterIterator as a result of
the formatting of the passed Object.
formatToCharacterIterator in class FormatAttributedCharacterIterator.
NullPointerException - if value is null.
IllegalArgumentException - if value is not an instance of
Number.public Currency getCurrency()
DecimalFormatSymbols used by this
DecimalFormat.
getCurrency in class NumberFormatCurrency if
the currency code matches a known one, null otherwise.public DecimalFormatSymbols getDecimalFormatSymbols()
public int getGroupingSize()
DecimalFormatSymbols.getDecimalSeparator()
public int getMultiplier()
public String getNegativePrefix()
public String getNegativeSuffix()
public String getPositivePrefix()
public String getPositiveSuffix()
public boolean isDecimalSeparatorAlwaysShown()
public void setParseBigDecimal(boolean newValue)
parse(java.lang.String, java.text.ParsePosition)
should return a BigDecimal or not.
newValue - public boolean isParseBigDecimal()
true if
parse(java.lang.String, java.text.ParsePosition) returns
a BigDecimal, false otherwise.
The default return value for this method is false.
true if the parse method returns a BigDecimal,
false otherwise.setParseBigDecimal(boolean)
public Number parse(String str,
ParsePosition pos)
Number.
The parsing starts at pos, which is updated as the parser
consume characters in the passed string.
On error, the Position object index is not updated, while
error position is set appropriately, an null is returned.
parse in class NumberFormatstr - The string to parse.pos - The desired ParsePosition.
Numberpublic void setCurrency(Currency currency)
Currency on the
DecimalFormatSymbols used, which also sets the
currency symbols on those symbols.
setCurrency in class NumberFormatcurrency - The new Currency on the
DecimalFormatSymbols.public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
newSymbols - the symbols (null not permitted).public void setDecimalSeparatorAlwaysShown(boolean newValue)
true if you want the decimal separator to be
always shown, false otherwise.
newValue - true if you want the decimal separator to be
always shown, false otherwise.public void setGroupingSize(int groupSize)
123456, with a grouping
size of 3, is rendered 123,456.
groupSize - The number of digits used while grouping portions
of the integer part of a number.public void setMaximumIntegerDigits(int newValue)
newvalue and 309. Any value below zero will be
replaced by zero.
setMaximumIntegerDigits in class NumberFormatnewValue - The new maximum integer digits value.public void setMinimumIntegerDigits(int newValue)
newvalue and 309. Any value below zero will be
replaced by zero.
setMinimumIntegerDigits in class NumberFormatnewValue - The new minimum integer digits value.public void setMaximumFractionDigits(int newValue)
newvalue and 309. Any value below zero will be
replaced by zero.
setMaximumFractionDigits in class NumberFormatnewValue - The new maximum fraction digits value.public void setMinimumFractionDigits(int newValue)
newvalue and 309. Any value below zero will be
replaced by zero.
setMinimumFractionDigits in class NumberFormatnewValue - The new minimum fraction digits value.public void setMultiplier(int newValue)
newValue - the new value for multiplier.public void setNegativePrefix(String newValue)
newValue - The new negative prefix.public void setNegativeSuffix(String newValue)
newValue - The new negative suffix.public void setPositivePrefix(String newValue)
newValue - The new positive prefix.public void setPositiveSuffix(String newValue)
newValue - The new positive suffix.public String toLocalizedPattern()
String with the formatting pattern.toPattern()public String toPattern()
String with the formatting pattern.toLocalizedPattern()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||