java.text
Class DecimalFormat
- Cloneable, Serializable
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.
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.
|
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(Object obj, StringBuffer sbuf, FieldPosition pos) - Produce a formatted
String representation of this object.
|
StringBuffer | format(long number, StringBuffer dest, FieldPosition fieldPos) - Produce a formatted
String representation of this long.
|
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.
|
equals , format , format , format , format , format , getAvailableLocales , getCurrency , getCurrencyInstance , getCurrencyInstance , getInstance , getInstance , getIntegerInstance , getIntegerInstance , getMaximumFractionDigits , getMaximumIntegerDigits , getMinimumFractionDigits , getMinimumIntegerDigits , getNumberInstance , getNumberInstance , getPercentInstance , getPercentInstance , hashCode , isGroupingUsed , isParseIntegerOnly , parse , parse , parseObject , setCurrency , setGroupingUsed , setMaximumFractionDigits , setMaximumIntegerDigits , setMinimumFractionDigits , setMinimumIntegerDigits , setParseIntegerOnly |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
DecimalFormat
public DecimalFormat()
Constructs a DecimalFormat
which uses the default
pattern and symbols.
DecimalFormat
public DecimalFormat(String pattern)
Constructs a DecimalFormat
which uses the given
pattern and the default symbols for formatting and parsing.
pattern
- the non-localized pattern to use.
DecimalFormat
public DecimalFormat(String pattern,
DecimalFormatSymbols symbols)
Constructs a 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.
applyLocalizedPattern
public void applyLocalizedPattern(String pattern)
Apply the given localized patern to the current DecimalFormat object.
pattern
- The localized pattern to apply.
applyPattern
public void applyPattern(String pattern)
Apply the given localized pattern to the current DecimalFormat object.
pattern
- The localized pattern to apply.
equals
public boolean equals(Object obj)
Tests this instance for equality with an arbitrary object. This method
returns
true
if:
obj
is not null
;obj
is an instance of DecimalFormat
;- this instance and
obj
have the same attributes;
- equals in interface NumberFormat
obj
- the object (null
permitted).
format
public StringBuffer format(double number,
StringBuffer dest,
FieldPosition fieldPos)
Produce a formatted
String
representation of this double.
- format in interface NumberFormat
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.
- The String representation of this long.
format
public final StringBuffer format(Object obj,
StringBuffer sbuf,
FieldPosition pos)
Produce a formatted
String
representation of this object.
The passed object must be of type number.
- format in interface NumberFormat
obj
- 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.
- The String representation of this long.
format
public StringBuffer format(long number,
StringBuffer dest,
FieldPosition fieldPos)
Produce a formatted
String
representation of this long.
- format in interface NumberFormat
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.
- The String representation of this long.
getCurrency
public Currency getCurrency()
Returns the currency corresponding to the currency symbol stored
in the instance of DecimalFormatSymbols
used by this
DecimalFormat
.
- getCurrency in interface NumberFormat
- A new instance of
Currency
if
the currency code matches a known one, null otherwise.
getGroupingSize
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 by
DecimalFormatSymbols.getDecimalSeparator()
- The interval used between a grouping separator and the next.
getMultiplier
public int getMultiplier()
Gets the multiplier used in percent and similar formats.
- The multiplier used in percent and similar formats.
isParseBigDecimal
public boolean isParseBigDecimal()
Returns 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.
parse
public Number parse(String str,
ParsePosition pos)
This method parses the specified string into a 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 interface NumberFormat
str
- The string to parse.pos
- The desired ParsePosition
.
setCurrency
public void setCurrency(Currency currency)
Sets the Currency
on the
DecimalFormatSymbols
used, which also sets the
currency symbols on those symbols.
- setCurrency in interface NumberFormat
currency
- The new Currency
on the
DecimalFormatSymbols
.
setDecimalFormatSymbols
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
Sets the symbols used by this instance. This method makes a copy of
the supplied symbols.
newSymbols
- the symbols (null
not permitted).
setDecimalSeparatorAlwaysShown
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.
Pass 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.
setGroupingSize
public void setGroupingSize(int groupSize)
Sets the number of digits used to group portions of the integer part of
the number. For example, the number 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.
setMaximumFractionDigits
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 between
newvalue
and 309. Any value below zero will be
replaced by zero.
- setMaximumFractionDigits in interface NumberFormat
newValue
- The new maximum fraction digits value.
setMaximumIntegerDigits
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 between
newvalue
and 309. Any value below zero will be
replaced by zero.
- setMaximumIntegerDigits in interface NumberFormat
newValue
- The new maximum integer digits value.
setMinimumFractionDigits
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 between
newvalue
and 309. Any value below zero will be
replaced by zero.
- setMinimumFractionDigits in interface NumberFormat
newValue
- The new minimum fraction digits value.
setMinimumIntegerDigits
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 between
newvalue
and 309. Any value below zero will be
replaced by zero.
- setMinimumIntegerDigits in interface NumberFormat
newValue
- The new minimum integer digits value.
setMultiplier
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.
newValue
- the new value for multiplier.
setNegativePrefix
public void setNegativePrefix(String newValue)
Sets the negative prefix.
newValue
- The new negative prefix.
setNegativeSuffix
public void setNegativeSuffix(String newValue)
Sets the negative suffix.
newValue
- The new negative suffix.
setParseBigDecimal
public void setParseBigDecimal(boolean newValue)
Define if
parse(java.lang.String, java.text.ParsePosition)
should return a
BigDecimal
or not.
setPositivePrefix
public void setPositivePrefix(String newValue)
Sets the positive prefix.
newValue
- The new positive prefix.
setPositiveSuffix
public void setPositiveSuffix(String newValue)
Sets the new positive suffix.
newValue
- The new positive suffix.
toLocalizedPattern
public String toLocalizedPattern()
This method returns a string with the formatting pattern being used
by this object. The string is localized.
- A localized
String
with the formatting pattern.
toPattern
public String toPattern()
This method returns a string with the formatting pattern being used
by this object. The string is not localized.
- A
String
with the formatting pattern.
DecimalFormat.java -- Formats and parses numbers
Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2012 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.