GeezerVison is showing docs.oracle.com — DecimalFormat (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.text
Class DecimalFormat
-
-
Method Summary
All Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
void |
applyLocalizedPattern(String pattern) |
Apply the given pattern to this Format object.
|
void |
applyPattern(String pattern) |
Apply the given pattern to this Format object.
|
Object |
clone() |
Standard override; no change in semantics.
|
boolean |
equals(Object obj) |
Overrides equals
|
StringBuffer |
format(double number,
StringBuffer result,
FieldPosition fieldPosition) |
Formats a double to produce a string.
|
StringBuffer |
format(long number,
StringBuffer result,
FieldPosition fieldPosition) |
Format a long to produce a string.
|
StringBuffer |
format(Object number,
StringBuffer toAppendTo,
FieldPosition pos) |
Formats a number and appends the resulting text to the given string
buffer.
|
AttributedCharacterIterator |
formatToCharacterIterator(Object obj) |
Formats an Object producing an AttributedCharacterIterator.
|
Currency |
getCurrency() |
Gets the currency used by this decimal format when formatting
currency values.
|
DecimalFormatSymbols |
getDecimalFormatSymbols() |
Returns a copy of the decimal format symbols, which is generally not
changed by the programmer or user.
|
int |
getGroupingSize() |
Return the grouping size.
|
int |
getMaximumFractionDigits() |
Gets the maximum number of digits allowed in the fraction portion of a
number.
|
int |
getMaximumIntegerDigits() |
Gets the maximum number of digits allowed in the integer portion of a
number.
|
int |
getMinimumFractionDigits() |
Gets the minimum number of digits allowed in the fraction portion of a
number.
|
int |
getMinimumIntegerDigits() |
Gets the minimum number of digits allowed in the integer portion of a
number.
|
int |
getMultiplier() |
Gets the multiplier for use in percent, per mille, and similar
formats.
|
String |
getNegativePrefix() |
Get the negative prefix.
|
String |
getNegativeSuffix() |
Get the negative suffix.
|
String |
getPositivePrefix() |
Get the positive prefix.
|
String |
getPositiveSuffix() |
Get the positive suffix.
|
RoundingMode |
getRoundingMode() |
|
int |
hashCode() |
Overrides hashCode
|
boolean |
isDecimalSeparatorAlwaysShown() |
Allows you to get the behavior of the decimal separator with integers.
|
boolean |
isParseBigDecimal() |
|
Number |
parse(String text,
ParsePosition pos) |
Parses text from a string to produce a Number.
|
void |
setCurrency(Currency currency) |
Sets the currency used by this number format when formatting
currency values.
|
void |
setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) |
Sets the decimal format symbols, which is generally not changed
by the programmer or user.
|
void |
setDecimalSeparatorAlwaysShown(boolean newValue) |
Allows you to set the behavior of the decimal separator with integers.
|
void |
setGroupingSize(int newValue) |
Set the grouping size.
|
void |
setGroupingUsed(boolean newValue) |
Set whether or not grouping will be used in this format.
|
void |
setMaximumFractionDigits(int newValue) |
Sets the maximum number of digits allowed in the fraction portion of a
number.
|
void |
setMaximumIntegerDigits(int newValue) |
Sets the maximum number of digits allowed in the integer portion of a
number.
|
void |
setMinimumFractionDigits(int newValue) |
Sets the minimum number of digits allowed in the fraction portion of a
number.
|
void |
setMinimumIntegerDigits(int newValue) |
Sets the minimum number of digits allowed in the integer portion of a
number.
|
void |
setMultiplier(int newValue) |
Sets the multiplier for use in percent, per mille, and similar
formats.
|
void |
setNegativePrefix(String newValue) |
Set the negative prefix.
|
void |
setNegativeSuffix(String newValue) |
Set the negative suffix.
|
void |
setParseBigDecimal(boolean newValue) |
|
void |
setPositivePrefix(String newValue) |
Set the positive prefix.
|
void |
setPositiveSuffix(String newValue) |
Set the positive suffix.
|
void |
setRoundingMode(RoundingMode roundingMode) |
|
String |
toLocalizedPattern() |
Synthesizes a localized pattern string that represents the current
state of this Format object.
|
String |
toPattern() |
Synthesizes a pattern string that represents the current state
of this Format object.
|
-
Methods inherited from class java.text.NumberFormat
format, format, getAvailableLocales, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getNumberInstance, getNumberInstance, getPercentInstance, getPercentInstance, isGroupingUsed, isParseIntegerOnly, parse, parseObject, setParseIntegerOnly
-
-
Method Detail
-
format
public StringBuffer format(double number,
StringBuffer result,
FieldPosition fieldPosition)
Formats a double to produce a string.
- Specified by:
format in class NumberFormat
- Parameters:
number - The double to format
result - where the text is to be appended
fieldPosition - On input: an alignment field, if desired.
On output: the offsets of the alignment field.
- Returns:
- The formatted number string
- Throws:
ArithmeticException - if rounding is needed with rounding
mode being set to RoundingMode.UNNECESSARY
- See Also:
FieldPosition
-
format
public StringBuffer format(long number,
StringBuffer result,
FieldPosition fieldPosition)
Format a long to produce a string.
- Specified by:
format in class NumberFormat
- Parameters:
number - The long to format
result - where the text is to be appended
fieldPosition - On input: an alignment field, if desired.
On output: the offsets of the alignment field.
- Returns:
- The formatted number string
- Throws:
ArithmeticException - if rounding is needed with rounding
mode being set to RoundingMode.UNNECESSARY
- See Also:
FieldPosition
-
getDecimalFormatSymbols
public DecimalFormatSymbols getDecimalFormatSymbols()
Returns a copy of the decimal format symbols, which is generally not
changed by the programmer or user.
- Returns:
- a copy of the desired DecimalFormatSymbols
- See Also:
DecimalFormatSymbols
-
setDecimalFormatSymbols
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
Sets the decimal format symbols, which is generally not changed
by the programmer or user.
- Parameters:
newSymbols - desired DecimalFormatSymbols
- See Also:
DecimalFormatSymbols
-
getMultiplier
public int getMultiplier()
Gets the multiplier for use in percent, per mille, and similar
formats.
- Returns:
- the multiplier
- See Also:
setMultiplier(int)
-
setMaximumIntegerDigits
public void setMaximumIntegerDigits(int newValue)
Sets the maximum number of digits allowed in the integer portion of a
number.
For formatting numbers other than BigInteger and
BigDecimal objects, the lower of newValue and
309 is used. Negative input values are replaced with 0.
- Overrides:
setMaximumIntegerDigits in class NumberFormat
- Parameters:
newValue - the maximum number of integer digits to be shown; if
less than zero, then zero is used. The concrete subclass may enforce an
upper limit to this value appropriate to the numeric type being formatted.
- See Also:
NumberFormat.setMaximumIntegerDigits(int)
-
setMinimumIntegerDigits
public void setMinimumIntegerDigits(int newValue)
Sets the minimum number of digits allowed in the integer portion of a
number.
For formatting numbers other than BigInteger and
BigDecimal objects, the lower of newValue and
309 is used. Negative input values are replaced with 0.
- Overrides:
setMinimumIntegerDigits in class NumberFormat
- Parameters:
newValue - the minimum number of integer digits to be shown; if
less than zero, then zero is used. The concrete subclass may enforce an
upper limit to this value appropriate to the numeric type being formatted.
- See Also:
NumberFormat.setMinimumIntegerDigits(int)
-
setMaximumFractionDigits
public void setMaximumFractionDigits(int newValue)
Sets the maximum number of digits allowed in the fraction portion of a
number.
For formatting numbers other than BigInteger and
BigDecimal objects, the lower of newValue and
340 is used. Negative input values are replaced with 0.
- Overrides:
setMaximumFractionDigits in class NumberFormat
- Parameters:
newValue - the maximum number of fraction digits to be shown; if
less than zero, then zero is used. The concrete subclass may enforce an
upper limit to this value appropriate to the numeric type being formatted.
- See Also:
NumberFormat.setMaximumFractionDigits(int)
-
setMinimumFractionDigits
public void setMinimumFractionDigits(int newValue)
Sets the minimum number of digits allowed in the fraction portion of a
number.
For formatting numbers other than BigInteger and
BigDecimal objects, the lower of newValue and
340 is used. Negative input values are replaced with 0.
- Overrides:
setMinimumFractionDigits in class NumberFormat
- Parameters:
newValue - the minimum number of fraction digits to be shown; if
less than zero, then zero is used. The concrete subclass may enforce an
upper limit to this value appropriate to the numeric type being formatted.
- See Also:
NumberFormat.setMinimumFractionDigits(int)
-
getMaximumIntegerDigits
public int getMaximumIntegerDigits()
Gets the maximum number of digits allowed in the integer portion of a
number.
For formatting numbers other than BigInteger and
BigDecimal objects, the lower of the return value and
309 is used.
- Overrides:
getMaximumIntegerDigits in class NumberFormat
- Returns:
- the maximum number of digits
- See Also:
setMaximumIntegerDigits(int)
-
getMinimumIntegerDigits
public int getMinimumIntegerDigits()
Gets the minimum number of digits allowed in the integer portion of a
number.
For formatting numbers other than BigInteger and
BigDecimal objects, the lower of the return value and
309 is used.
- Overrides:
getMinimumIntegerDigits in class NumberFormat
- Returns:
- the minimum number of digits
- See Also:
setMinimumIntegerDigits(int)
-
getMaximumFractionDigits
public int getMaximumFractionDigits()
Gets the maximum number of digits allowed in the fraction portion of a
number.
For formatting numbers other than BigInteger and
BigDecimal objects, the lower of the return value and
340 is used.
- Overrides:
getMaximumFractionDigits in class NumberFormat
- Returns:
- the maximum number of digits.
- See Also:
setMaximumFractionDigits(int)
-
getMinimumFractionDigits
public int getMinimumFractionDigits()
Gets the minimum number of digits allowed in the fraction portion of a
number.
For formatting numbers other than BigInteger and
BigDecimal objects, the lower of the return value and
340 is used.
- Overrides:
getMinimumFractionDigits in class NumberFormat
- Returns:
- the minimum number of digits
- See Also:
setMinimumFractionDigits(int)
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|