GNU Classpath (0.95) | |
Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.text.Format
java.text.NumberFormat
java.text.DecimalFormat
public class DecimalFormat
extends NumberFormat
NumberFormat
base class.
Nested Class Summary |
Nested classes/interfaces inherited from class java.text.NumberFormat | |
NumberFormat.Field |
Nested classes/interfaces inherited from class java.text.Format | |
Format.Field |
Field Summary |
Fields inherited from class java.text.NumberFormat | |
FRACTION_FIELD , INTEGER_FIELD |
Constructor Summary | |
| |
| |
|
Method Summary | |
void |
|
void |
|
Object |
|
boolean | |
StringBuffer |
|
StringBuffer |
|
StringBuffer |
|
AttributedCharacterIterator |
|
Currency |
|
DecimalFormatSymbols |
|
int |
|
int |
|
String |
|
String |
|
String |
|
String |
|
int |
|
boolean | |
boolean |
|
Number |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
String |
|
Methods inherited from class java.text.Format | |
clone , format , format , formatToCharacterIterator , parseObject , parseObject |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public DecimalFormat()
Constructs aDecimalFormat
which uses the default pattern and symbols.
public DecimalFormat(String pattern)
Constructs aDecimalFormat
which uses the given pattern and the default symbols for formatting and parsing.
- Parameters:
pattern
- the non-localized pattern to use.
- Throws:
NullPointerException
- if any argument is null.IllegalArgumentException
- if the pattern is invalid.
public DecimalFormat(String pattern, DecimalFormatSymbols symbols)
Constructs aDecimalFormat
using the given pattern and formatting symbols. This construction method is used to give complete control over the formatting process.
- Parameters:
pattern
- the non-localized pattern to use.symbols
- the set of symbols used for parsing and formatting.
- Throws:
NullPointerException
- if any argument is null.IllegalArgumentException
- if the pattern is invalid.
public void applyLocalizedPattern(String pattern)
Apply the given localized patern to the current DecimalFormat object.
- Parameters:
pattern
- The localized pattern to apply.
- Throws:
IllegalArgumentException
- if the given pattern is invalid.NullPointerException
- if the input pattern is null.
public void applyPattern(String pattern)
Apply the given localized pattern to the current DecimalFormat object.
- Parameters:
pattern
- The localized pattern to apply.
- Throws:
IllegalArgumentException
- if the given pattern is invalid.NullPointerException
- if the input pattern is null.
public boolean equals(Object obj)
Tests this instance for equality with an arbitrary object. This method returnstrue
if:
obj
is notnull
;obj
is an instance ofDecimalFormat
;- this instance and
obj
have the same attributes;
- Overrides:
- equals in interface NumberFormat
- Parameters:
obj
- the object (null
permitted).
- Returns:
- A boolean.
public StringBuffer format(double number, StringBuffer dest, FieldPosition fieldPos)
Produce a formattedString
representation of this double.
- Overrides:
- format in interface NumberFormat
- Parameters:
number
- 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.
- Returns:
- The String representation of this long.
- Throws:
NullPointerException
- ifdest
or fieldPos are null
public StringBuffer format(Object obj, StringBuffer sbuf, FieldPosition pos)
Produce a formattedString
representation of this object. The passed object must be of type number.
- Overrides:
- format in interface NumberFormat
- Parameters:
obj
- TheNumber
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.
- Returns:
- The String representation of this long.
public StringBuffer format(long number, StringBuffer dest, FieldPosition fieldPos)
Produce a formattedString
representation of this long.
- Overrides:
- format in interface NumberFormat
- Parameters:
number
- 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.
- Returns:
- The String representation of this long.
public AttributedCharacterIterator formatToCharacterIterator(Object value)
Return anAttributedCharacterIterator
as a result of the formatting of the passedObject
.
- Overrides:
- formatToCharacterIterator in interface Format
- Returns:
- An
AttributedCharacterIterator
.
- Throws:
NullPointerException
- if value isnull
.IllegalArgumentException
- if value is not an instance ofNumber
.
public Currency getCurrency()
Returns the currency corresponding to the currency symbol stored in the instance ofDecimalFormatSymbols
used by thisDecimalFormat
.
- Overrides:
- getCurrency in interface NumberFormat
- Returns:
- A new instance of
Currency
if the currency code matches a known one, null otherwise.
public DecimalFormatSymbols getDecimalFormatSymbols()
Returns a copy of the symbols used by this instance.
- Returns:
- A copy of the symbols.
public int getGroupingSize()
Gets the interval used between a grouping separator and the next. For example, a grouping size of 3 means that the number 1234 is formatted as 1,234. The actual character used as grouping separator depends on the locale and is defined byDecimalFormatSymbols.getDecimalSeparator()
- Returns:
- The interval used between a grouping separator and the next.
public int getMultiplier()
Gets the multiplier used in percent and similar formats.
- Returns:
- The multiplier used in percent and similar formats.
public String getNegativePrefix()
Gets the negative prefix.
- Returns:
- The negative prefix.
public String getNegativeSuffix()
Gets the negative suffix.
- Returns:
- The negative suffix.
public String getPositivePrefix()
Gets the positive prefix.
- Returns:
- The positive prefix.
public String getPositiveSuffix()
Gets the positive suffix.
- Returns:
- The positive suffix.
public int hashCode()
Returns a hash code for this object.
- Overrides:
- hashCode in interface NumberFormat
- Returns:
- A hash code.
public boolean isParseBigDecimal()
Returnstrue
ifparse(java.lang.String, java.text.ParsePosition)
returns aBigDecimal
,false
otherwise. The default return value for this method isfalse
.
- Returns:
true
if the parse method returns aBigDecimal
,false
otherwise.
- Since:
- 1.5
- See Also:
setParseBigDecimal(boolean)
public Number parse(String str, ParsePosition pos)
This method parses the specified string into aNumber
. The parsing starts atpos
, which is updated as the parser consume characters in the passed string. On error, thePosition
object index is not updated, while error position is set appropriately, annull
is returned.
- Overrides:
- parse in interface NumberFormat
- Parameters:
str
- The string to parse.pos
- The desiredParsePosition
.
- Returns:
- The parsed
Number
public void setCurrency(Currency currency)
Sets theCurrency
on theDecimalFormatSymbols
used, which also sets the currency symbols on those symbols.
- Overrides:
- setCurrency in interface NumberFormat
- Parameters:
currency
- The newCurrency
on theDecimalFormatSymbols
.
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
Sets the symbols used by this instance. This method makes a copy of the supplied symbols.
- Parameters:
newSymbols
- the symbols (null
not permitted).
public void setDecimalSeparatorAlwaysShown(boolean newValue)
Define if the decimal separator should be always visible or only visible when needed. This method as effect only on integer values. Passtrue
if you want the decimal separator to be always shown,false
otherwise.
- Parameters:
newValue
- true if you want the decimal separator to be always shown,false
otherwise.
public void setGroupingSize(int groupSize)
Sets the number of digits used to group portions of the integer part of the number. For example, the number123456
, with a grouping size of 3, is rendered123,456
.
- Parameters:
groupSize
- The number of digits used while grouping portions of the integer part of a number.
public void setMaximumFractionDigits(int newValue)
Sets the maximum number of digits allowed in the fraction portion of a number to the specified value. The new value will be the choosen as the minimum betweennewvalue
and 309. Any value below zero will be replaced by zero.
- Overrides:
- setMaximumFractionDigits in interface NumberFormat
- Parameters:
newValue
- The new maximum fraction digits value.
public void setMaximumIntegerDigits(int newValue)
Sets the maximum number of digits allowed in the integer portion of a number to the specified value. The new value will be the choosen as the minimum betweennewvalue
and 309. Any value below zero will be replaced by zero.
- Overrides:
- setMaximumIntegerDigits in interface NumberFormat
- Parameters:
newValue
- The new maximum integer digits value.
public void setMinimumFractionDigits(int newValue)
Sets the minimum number of digits allowed in the fraction portion of a number to the specified value. The new value will be the choosen as the minimum betweennewvalue
and 309. Any value below zero will be replaced by zero.
- Overrides:
- setMinimumFractionDigits in interface NumberFormat
- Parameters:
newValue
- The new minimum fraction digits value.
public void setMinimumIntegerDigits(int newValue)
Sets the minimum number of digits allowed in the integer portion of a number to the specified value. The new value will be the choosen as the minimum betweennewvalue
and 309. Any value below zero will be replaced by zero.
- Overrides:
- setMinimumIntegerDigits in interface NumberFormat
- Parameters:
newValue
- The new minimum integer digits value.
public void setMultiplier(int newValue)
Sets the multiplier for use in percent and similar formats. For example, for percent set the multiplier to 100, for permille, set the miltiplier to 1000.
- Parameters:
newValue
- the new value for multiplier.
public void setNegativePrefix(String newValue)
Sets the negative prefix.
- Parameters:
newValue
- The new negative prefix.
public void setNegativeSuffix(String newValue)
Sets the negative suffix.
- Parameters:
newValue
- The new negative suffix.
public void setParseBigDecimal(boolean newValue)
Define ifparse(java.lang.String, java.text.ParsePosition)
should return aBigDecimal
or not.
- Parameters:
newValue
-
public void setPositivePrefix(String newValue)
Sets the positive prefix.
- Parameters:
newValue
- The new positive prefix.
public void setPositiveSuffix(String newValue)
Sets the new positive suffix.
- Parameters:
newValue
- The new positive suffix.
public String toLocalizedPattern()
This method returns a string with the formatting pattern being used by this object. The string is localized.
- Returns:
- A localized
String
with the formatting pattern.
- See Also:
toPattern()
public String toPattern()
This method returns a string with the formatting pattern being used by this object. The string is not localized.
- Returns:
- A
String
with the formatting pattern.
- See Also:
toLocalizedPattern()
GNU Classpath (0.95) |