Build 1.0_r1(from source)

java.text
Class DecimalFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.NumberFormat
          extended by java.text.DecimalFormat
All Implemented Interfaces:
Serializable, Cloneable

public class DecimalFormat
extends NumberFormat

DecimalFormat is used to format and parse numbers, both integers and fractions, based on a pattern. The pattern characters used can be either localized or non-localized.

See Also:
Serialized Form

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 new DecimalFormat for formatting and parsing numbers for the default Locale.
DecimalFormat(String pattern)
          Constructs a new DecimalFormat using the specified non-localized pattern and the DecimalFormatSymbols for the default Locale.
DecimalFormat(String pattern, DecimalFormatSymbols value)
          Constructs a new DecimalFormat using the specified non-localized pattern and DecimalFormatSymbols.
 
Method Summary
 void applyLocalizedPattern(String pattern)
          Changes the pattern of this DecimalFormat to the specified pattern which uses localized pattern characters.
 void applyPattern(String pattern)
          Changes the pattern of this SimpleDateFormat to the specified pattern which uses non-localized pattern characters.
 Object clone()
          Returns a new instance of DecimalFormat with the same pattern and properties as this DecimalFormat.
 boolean equals(Object object)
          Compares the specified object to this DecimalFormat and answer if they are equal.
 StringBuffer format(double value, StringBuffer buffer, FieldPosition position)
          Formats the double value into the specified StringBuffer using the pattern of this DecimalFormat.
 StringBuffer format(long value, StringBuffer buffer, FieldPosition position)
          Formats the long value into the specified StringBuffer using the pattern of this DecimalFormat.
 StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos)
          Formats the number into the specified StringBuffer using the pattern of this DecimalFormat.
 AttributedCharacterIterator formatToCharacterIterator(Object object)
          Formats the specified object using the rules of this DecimalNumberFormat and returns an AttributedCharacterIterator with the formatted number and attributes.
 Currency getCurrency()
          Returns the currency used by this decimal format.
 DecimalFormatSymbols getDecimalFormatSymbols()
          Returns the DecimalFormatSymbols used by this DecimalFormat.
 int getGroupingSize()
          Returns the number of digits grouped together by the grouping separator.
 int getMultiplier()
          Returns the multiplier which is applied to the number before formatting or after parsing.
 String getNegativePrefix()
          Returns the prefix which is formatted or parsed before a negative number.
 String getNegativeSuffix()
          Returns the suffix which is formatted or parsed after a negative number.
 String getPositivePrefix()
          Returns the prefix which is formatted or parsed before a positive number.
 String getPositiveSuffix()
          Returns the suffix which is formatted or parsed after a positive number.
 int hashCode()
          Returns an integer hash code for the receiver.
 boolean isDecimalSeparatorAlwaysShown()
          Returns whether the decimal separator is shown when there are no fractional digits.
 boolean isGroupingUsed()
          This value indicates whether grouping will be used in this format.
 boolean isParseBigDecimal()
          This value indicates whether the return object of the parse operation will be of type BigDecimal.
 boolean isParseIntegerOnly()
          Returns true if this DecimalFormat's all resulting number will be of type java.lang.Integer
 Number parse(String string, ParsePosition position)
          Parse a Long or Double from the specified String starting at the index specified by the ParsePosition.
 void setCurrency(Currency currency)
          Sets the currency used by this decimal format.
 void setDecimalFormatSymbols(DecimalFormatSymbols value)
          Sets the DecimalFormatSymbols used by this DecimalFormat.
 void setDecimalSeparatorAlwaysShown(boolean value)
          Sets whether the decimal separator is shown when there are no fractional digits.
 void setGroupingSize(int value)
          Sets the number of digits grouped together by the grouping separator.
 void setGroupingUsed(boolean value)
          Sets whether or not grouping will be used in this format.
 void setMaximumFractionDigits(int value)
          Sets the maximum number of fraction digits that are printed when formatting.
 void setMaximumIntegerDigits(int value)
          Sets the maximum number of integer digits that are printed when formatting.
 void setMinimumFractionDigits(int value)
          Sets the minimum number of fraction digits that are printed when formatting.
 void setMinimumIntegerDigits(int value)
          Sets the minimum number of integer digits that are printed when formatting.
 void setMultiplier(int value)
          Sets the multiplier which is applied to the number before formatting or after parsing.
 void setNegativePrefix(String value)
          Sets the prefix which is formatted or parsed before a negative number.
 void setNegativeSuffix(String value)
          Sets the suffix which is formatted or parsed after a negative number.
 void setParseBigDecimal(boolean newValue)
          Let users change the behavior of a DecimalFormat, If set to true all the returned objects will be of type BigDecimal
 void setParseIntegerOnly(boolean value)
          When DecimalFormat is used to parsing, and this value is set to true, then all the resulting number will be of type java.lang.Integer.
 void setPositivePrefix(String value)
          Sets the prefix which is formatted or parsed before a positive number.
 void setPositiveSuffix(String value)
          Sets the suffix which is formatted or parsed after a positive number.
 String toLocalizedPattern()
          Returns the pattern of this DecimalFormat using localized pattern characters.
 String toPattern()
          Returns the pattern of this DecimalFormat using non-localized pattern characters.
 
Methods inherited from class java.text.NumberFormat
format, format, getAvailableLocales, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberInstance, getNumberInstance, getPattern, getPercentInstance, getPercentInstance, parse, parseObject
 
Methods inherited from class java.text.Format
convertPattern, format, getBundle, parseObject, upTo, upToWithQuotes
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DecimalFormat

public DecimalFormat()
Constructs a new DecimalFormat for formatting and parsing numbers for the default Locale.


DecimalFormat

public DecimalFormat(String pattern)
Constructs a new DecimalFormat using the specified non-localized pattern and the DecimalFormatSymbols for the default Locale.

Parameters:
pattern - the non-localized pattern
Throws:
IllegalArgumentException - when the pattern cannot be parsed

DecimalFormat

public DecimalFormat(String pattern,
                     DecimalFormatSymbols value)
Constructs a new DecimalFormat using the specified non-localized pattern and DecimalFormatSymbols.

Parameters:
pattern - the non-localized pattern
value - the DecimalFormatSymbols
Throws:
IllegalArgumentException - when the pattern cannot be parsed
Method Detail

applyLocalizedPattern

public void applyLocalizedPattern(String pattern)
Changes the pattern of this DecimalFormat to the specified pattern which uses localized pattern characters.

Parameters:
pattern - the localized pattern
Throws:
IllegalArgumentException - when the pattern cannot be parsed

applyPattern

public void applyPattern(String pattern)
Changes the pattern of this SimpleDateFormat to the specified pattern which uses non-localized pattern characters.

Parameters:
pattern - the non-localized pattern
Throws:
IllegalArgumentException - when the pattern cannot be parsed

clone

public Object clone()
Returns a new instance of DecimalFormat with the same pattern and properties as this DecimalFormat.

Overrides:
clone in class NumberFormat
Returns:
a shallow copy of this DecimalFormat
See Also:
Cloneable

equals

public boolean equals(Object object)
Compares the specified object to this DecimalFormat and answer if they are equal. The object must be an instance of DecimalFormat with the same pattern and properties.

Overrides:
equals in class NumberFormat
Parameters:
object - the object to compare with this object
Returns:
true if the specified object is equal to this DecimalFormat, false otherwise
See Also:
hashCode()

formatToCharacterIterator

public AttributedCharacterIterator formatToCharacterIterator(Object object)
Formats the specified object using the rules of this DecimalNumberFormat and returns an AttributedCharacterIterator with the formatted number and attributes.

Overrides:
formatToCharacterIterator in class Format
Parameters:
object - the object to format
Returns:
an AttributedCharacterIterator with the formatted number and attributes
Throws:
NullPointerException - when the object is null
IllegalArgumentException - when the object cannot be formatted by this Format

format

public StringBuffer format(double value,
                           StringBuffer buffer,
                           FieldPosition position)
Formats the double value into the specified StringBuffer using the pattern of this DecimalFormat. If the field specified by the FieldPosition is formatted, set the begin and end index of the formatted field in the FieldPosition.

Specified by:
format in class NumberFormat
Parameters:
value - the double to format
buffer - the StringBuffer
position - the FieldPosition
Returns:
the StringBuffer parameter buffer

format

public StringBuffer format(long value,
                           StringBuffer buffer,
                           FieldPosition position)
Formats the long value into the specified StringBuffer using the pattern of this DecimalFormat. If the field specified by the FieldPosition is formatted, set the begin and end index of the formatted field in the FieldPosition.

Specified by:
format in class NumberFormat
Parameters:
value - the long to format
buffer - the StringBuffer
position - the FieldPosition
Returns:
the StringBuffer parameter buffer

format

public final StringBuffer format(Object number,
                                 StringBuffer toAppendTo,
                                 FieldPosition pos)
Formats the number into the specified StringBuffer using the pattern of this DecimalFormat. If the field specified by the FieldPosition is formatted, set the begin and end index of the formatted field in the FieldPosition.

Overrides:
format in class NumberFormat
Parameters:
number - the object to format
toAppendTo - the StringBuffer
pos - the FieldPosition
Returns:
the StringBuffer parameter buffer
Throws:
IllegalArgumentException - if the given number is not instance of Number

getDecimalFormatSymbols

public DecimalFormatSymbols getDecimalFormatSymbols()
Returns the DecimalFormatSymbols used by this DecimalFormat.

Returns:
a DecimalFormatSymbols

getCurrency

public Currency getCurrency()
Returns the currency used by this decimal format.

Overrides:
getCurrency in class NumberFormat
Returns:
currency of DecimalFormatSymbols used by this decimal format
See Also:
DecimalFormatSymbols.getCurrency()

getGroupingSize

public int getGroupingSize()
Returns the number of digits grouped together by the grouping separator.

Returns:
the number of digits grouped together

getMultiplier

public int getMultiplier()
Returns the multiplier which is applied to the number before formatting or after parsing.

Returns:
the multiplier

getNegativePrefix

public String getNegativePrefix()
Returns the prefix which is formatted or parsed before a negative number.

Returns:
the negative prefix

getNegativeSuffix

public String getNegativeSuffix()
Returns the suffix which is formatted or parsed after a negative number.

Returns:
the negative suffix

getPositivePrefix

public String getPositivePrefix()
Returns the prefix which is formatted or parsed before a positive number.

Returns:
the positive prefix

getPositiveSuffix

public String getPositiveSuffix()
Returns the suffix which is formatted or parsed after a positive number.

Returns:
the positive suffix

hashCode

public int hashCode()
Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Overrides:
hashCode in class NumberFormat
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

isDecimalSeparatorAlwaysShown

public boolean isDecimalSeparatorAlwaysShown()
Returns whether the decimal separator is shown when there are no fractional digits.

Returns:
true if the decimal separator should always be formatted, false otherwise

isParseBigDecimal

public boolean isParseBigDecimal()
This value indicates whether the return object of the parse operation will be of type BigDecimal. This value will default to false.

Returns:
true and parse will always return BigDecimals, false and the type of the result will be Long or Double.

setParseIntegerOnly

public void setParseIntegerOnly(boolean value)
When DecimalFormat is used to parsing, and this value is set to true, then all the resulting number will be of type java.lang.Integer. Except that, NaN, positive and negative infinity are still returned as java.lang.Double In this implementation, com.ibm.icu4jni.text.DecimalFormat is wrapped to fulfill most of the format and parse feature. And this method is delegated to the wrapped instance of com.ibm.icu4jni.text.DecimalFormat.

Overrides:
setParseIntegerOnly in class NumberFormat
Parameters:
value - If set to true, all the resulting number will be of type java.lang.Integer except some special cases.

isParseIntegerOnly

public boolean isParseIntegerOnly()
Returns true if this DecimalFormat's all resulting number will be of type java.lang.Integer

Overrides:
isParseIntegerOnly in class NumberFormat
Returns:
true if this DecimalFormat's all resulting number will be of type java.lang.Integer

parse

public Number parse(String string,
                    ParsePosition position)
Parse a Long or Double from the specified String starting at the index specified by the ParsePosition. If the string is successfully parsed, the index of the ParsePosition is updated to the index following the parsed text.

Specified by:
parse in class NumberFormat
Parameters:
string - the String to parse
position - the ParsePosition, updated on return with the index following the parsed text, or on error the index is unchanged and the error index is set to the index where the error occurred
Returns:
a Long or Double resulting from the parse, or null if there is an error. The result will be a Long if the parsed number is an integer in the range of a long, otherwise the result is a Double.

setDecimalFormatSymbols

public void setDecimalFormatSymbols(DecimalFormatSymbols value)
Sets the DecimalFormatSymbols used by this DecimalFormat.

Parameters:
value - the DecimalFormatSymbols

setCurrency

public void setCurrency(Currency currency)
Sets the currency used by this decimal format. The min and max fraction digits remain the same.

Overrides:
setCurrency in class NumberFormat
Parameters:
currency -
See Also:
DecimalFormatSymbols.setCurrency(Currency)

setDecimalSeparatorAlwaysShown

public void setDecimalSeparatorAlwaysShown(boolean value)
Sets whether the decimal separator is shown when there are no fractional digits.

Parameters:
value - true if the decimal separator should always be formatted, false otherwise

setGroupingSize

public void setGroupingSize(int value)
Sets the number of digits grouped together by the grouping separator.

Parameters:
value - the number of digits grouped together

setGroupingUsed

public void setGroupingUsed(boolean value)
Sets whether or not grouping will be used in this format. Grouping affects both parsing and formatting.

Overrides:
setGroupingUsed in class NumberFormat
Parameters:
value - true if uses grouping,false otherwise.

isGroupingUsed

public boolean isGroupingUsed()
This value indicates whether grouping will be used in this format.

Overrides:
isGroupingUsed in class NumberFormat
Returns:
true if grouping is used,false otherwise.

setMaximumFractionDigits

public void setMaximumFractionDigits(int value)
Sets the maximum number of fraction digits that are printed when formatting. If the maximum is less than the number of fraction digits, the least significant digits are truncated. Limit the maximum to DOUBLE_FRACTION_DIGITS.

Overrides:
setMaximumFractionDigits in class NumberFormat
Parameters:
value - the maximum number of fraction digits

setMaximumIntegerDigits

public void setMaximumIntegerDigits(int value)
Sets the maximum number of integer digits that are printed when formatting. If the maximum is less than the number of integer digits, the most significant digits are truncated. Limit the maximum to DOUBLE_INTEGER_DIGITS.

Overrides:
setMaximumIntegerDigits in class NumberFormat
Parameters:
value - the maximum number of integer digits

setMinimumFractionDigits

public void setMinimumFractionDigits(int value)
Sets the minimum number of fraction digits that are printed when formatting. Limit the minimum to DOUBLE_FRACTION_DIGITS.

Overrides:
setMinimumFractionDigits in class NumberFormat
Parameters:
value - the minimum number of fraction digits

setMinimumIntegerDigits

public void setMinimumIntegerDigits(int value)
Sets the minimum number of integer digits that are printed when formatting. Limit the minimum to DOUBLE_INTEGER_DIGITS.

Overrides:
setMinimumIntegerDigits in class NumberFormat
Parameters:
value - the minimum number of integer digits

setMultiplier

public void setMultiplier(int value)
Sets the multiplier which is applied to the number before formatting or after parsing.

Parameters:
value - the multiplier

setNegativePrefix

public void setNegativePrefix(String value)
Sets the prefix which is formatted or parsed before a negative number.

Parameters:
value - the negative prefix

setNegativeSuffix

public void setNegativeSuffix(String value)
Sets the suffix which is formatted or parsed after a negative number.

Parameters:
value - the negative suffix

setPositivePrefix

public void setPositivePrefix(String value)
Sets the prefix which is formatted or parsed before a positive number.

Parameters:
value - the positive prefix

setPositiveSuffix

public void setPositiveSuffix(String value)
Sets the suffix which is formatted or parsed after a positive number.

Parameters:
value - the positive suffix

setParseBigDecimal

public void setParseBigDecimal(boolean newValue)
Let users change the behavior of a DecimalFormat, If set to true all the returned objects will be of type BigDecimal

Parameters:
newValue - true if all the returned objects should be type of BigDecimal

toLocalizedPattern

public String toLocalizedPattern()
Returns the pattern of this DecimalFormat using localized pattern characters.

Returns:
the localized pattern

toPattern

public String toPattern()
Returns the pattern of this DecimalFormat using non-localized pattern characters.

Returns:
the non-localized pattern

Build 1.0_r1(from source)

Please submit a feedback, bug or feature