APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.text

public Class DecimalFormat

extends NumberFormat
Class Inheritance
Imports
java.io.IOException, .InvalidObjectException, .ObjectInputStream, java.math.BigDecimal, .BigInteger, .RoundingMode, java.text.spi.NumberFormatProvider, java.util.ArrayList, .Currency, .Locale, .Objects, java.util.concurrent.atomic.AtomicInteger, .AtomicLong, sun.util.locale.provider.LocaleProviderAdapter, .ResourceBundleBasedAdapter

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers in a localized manner. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits. It also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123).

Getting a DecimalFormat

To obtain a standard decimal format for a specific locale, including the default locale, it is recommended to call one of the NumberFormat factory methods, such as NumberFormat#getInstance(). These factory methods may not always return a DecimalFormat depending on the locale-service provider implementation installed. Thus, to use an instance method defined by DecimalFormat, the NumberFormat returned by the factory method should be type checked before converted to DecimalFormat. If the installed locale-sensitive service implementation does not support the given Locale, the parent locale chain will be looked up, and a Locale used that is supported.

If the factory methods are not desired, use one of the constructors such as DecimalFormat(String pattern). See the Pattern section for more information on the pattern parameter.

Using DecimalFormat

The following is an example of formatting and parsing,
NumberFormat nFmt = NumberFormat.getCurrencyInstance(Locale.US); if (nFmt instanceof DecimalFormat dFmt) { // pattern match to DecimalFormat to use setPositiveSuffix(String) dFmt.setPositiveSuffix(" dollars"); dFmt.format(100000); // returns "$100,000.00 dollars" dFmt.parse("$100,000.00 dollars"); // returns 100000 }
NumberFormat nFmt = NumberFormat.getCurrencyInstance(Locale.US);
if (nFmt instanceof DecimalFormat dFmt) {
    // pattern match to DecimalFormat to use setPositiveSuffix(String)
    dFmt.setPositiveSuffix(" dollars");
    dFmt.format(100000); // returns "$100,000.00 dollars"
    dFmt.parse("$100,000.00 dollars"); // returns 100000
}

Formatting and Parsing

Rounding

When formatting, DecimalFormat can adjust its rounding using setRoundingMode(RoundingMode). By default, it uses RoundingMode.HALF_EVEN.

Digits

When formatting, DecimalFormat uses the ten consecutive characters starting with the localized zero digit defined in the DecimalFormatSymbols object as digits.

When parsing, these digits as well as all Unicode decimal digits, as defined by Character.digit, are recognized.

Integer and Fraction Digit Limits

The integer and fraction digit limits are set by either applying a pattern or using one of the appropriate DecimalFormat setter methods, for example, setMinimumFractionDigits(int). These limits have no impact on parsing behavior.

Special Values

Synchronization

Decimal formats are generally not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.

DecimalFormat Pattern

A DecimalFormat comprises a pattern and a set of symbols. The pattern may be set directly using applyPattern(), or indirectly using the various API methods. The symbols are stored in a DecimalFormatSymbols object. When using the NumberFormat factory methods, the pattern and symbols are created from the locale-sensitive service implementation installed.

DecimalFormat patterns have the following syntax:

Pattern:
        PositivePattern
        PositivePattern ; NegativePattern
PositivePattern:
        Prefixopt Number Suffixopt
NegativePattern:
        Prefixopt Number Suffixopt
Prefix:
        Any characters except the special pattern characters
Suffix:
        Any characters except the special pattern characters
Number:
        Integer Exponentopt
        Integer . Fraction Exponentopt
Integer:
        MinimumInteger
        #
        # Integer
        # , Integer
MinimumInteger:
        0
        0 MinimumInteger
        0 , MinimumInteger
Fraction:
        MinimumFractionopt OptionalFractionopt
MinimumFraction:
        0 MinimumFractionopt
OptionalFraction:
        # OptionalFractionopt
Exponent:
        E MinimumExponent
MinimumExponent:
        0 MinimumExponentopt

Special Pattern Characters

The special characters in the table below are interpreted syntactically when used in the DecimalFormat pattern. They must be quoted, unless noted otherwise, if they are to appear in the prefix or suffix as literals.

The characters in the Symbol column are used in non-localized patterns. The corresponding characters in the Localized Symbol column are used in localized patterns, with the characters in Symbol losing their syntactical meaning. Two exceptions are the currency sign (U+00A4) and quote (U+0027), which are not localized.

Non-localized patterns should be used when calling applyPattern(String). Localized patterns should be used when calling applyLocalizedPattern(String).

Chart showing symbol, location, localized, and meaning.
Symbol Localized Symbol Location Meaning
0 DecimalFormatSymbols#getZeroDigit() Number Digit
# DecimalFormatSymbols#getDigit() Number Digit, zero shows as absent
. DecimalFormatSymbols#getDecimalSeparator() Number Decimal separator or monetary decimal separator
- (U+002D) DecimalFormatSymbols#getMinusSign() Number Minus sign
, DecimalFormatSymbols#getGroupingSeparator() Number Grouping separator or monetary grouping separator
E DecimalFormatSymbols#getExponentSeparator() Number Separates mantissa and exponent in scientific notation. This value is case sensistive. Need not be quoted in prefix or suffix.
; DecimalFormatSymbols#getPatternSeparator() Subpattern boundary Separates positive and negative subpatterns
% DecimalFormatSymbols#getPercent() Prefix or suffix Multiply by 100 and show as percentage
‰ (U+2030) DecimalFormatSymbols#getPerMill() Prefix or suffix Multiply by 1000 and show as per mille value
¤ (U+00A4) n/a (not localized) Prefix or suffix Currency sign, replaced by currency symbol. If doubled, replaced by international currency symbol. If present in a pattern, the monetary decimal/grouping separators are used instead of the decimal/grouping separators.
' (U+0027) n/a (not localized) Prefix or suffix Used to quote special characters in a prefix or suffix, for example, "'#'#" formats 123 to "#123". To create a single quote itself, use two in a row: "# o''clock".

Maximum Digits Derivation

For any given DecimalFormat pattern, if the pattern is not in scientific notation, the maximum number of integer digits will not be derived from the pattern, and instead set to Integer#MAX_VALUE. Otherwise, if the pattern is in scientific notation, the maximum number of integer digits will be derived from the pattern. This derivation is detailed in the Scientific Notation section. setMaximumIntegerDigits(int) can be used to manually adjust the maximum integer digits.

Negative Subpatterns

A DecimalFormat pattern contains a positive and negative subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a prefix, numeric part, and suffix. The negative subpattern is optional; if absent, then the positive subpattern prefixed with the minus sign '-' (U+002D HYPHEN-MINUS) is used as the negative subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are all the same as the positive pattern. That means that "#,##0.0#;(#)" produces precisely the same behavior as "#,##0.0#;(#,##0.0#)". In lenient parsing mode, loose matching of the minus sign pattern is enabled, following the LDML’s loose matching specification.

The prefixes, suffixes, and various symbols used for infinity, digits, grouping separators, decimal separators, etc. may be set to arbitrary values, and they will appear properly during formatting. However, care must be taken that the symbols and strings do not conflict, or parsing will be unreliable. For example, either the positive and negative prefixes or the suffixes must be distinct for DecimalFormat.parse() to be able to distinguish positive from negative values. (If they are identical, then DecimalFormat will behave as if no negative subpattern was specified.) Another example is that the decimal separator and grouping separator should be distinct characters, or parsing will be impossible.

Grouping Separator

The grouping separator is commonly used for thousands, but in some locales it separates ten-thousands. The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. For example, "#,##,###,####" == "######,####" == "##,####,####".

Scientific Notation

Numbers in scientific notation are expressed as the product of a mantissa and a power of ten, for example, 1234 can be expressed as 1.234 x 10^3. The mantissa is often in the range 1.0 ≤ x < 10.0, but it need not be. DecimalFormat can be instructed to format and parse scientific notation only via a pattern; there is currently no factory method that creates a scientific notation format. In a pattern, the exponent character immediately followed by one or more digit characters indicates scientific notation. Example: "0.###E0" formats the number 1234 as "1.234E3".

Implementation Specification

When formatting a Number other than BigInteger and BigDecimal, 309 is used as the upper limit for integer digits, and 340 as the upper limit for fraction digits. This occurs, even if one of the DecimalFormat getter methods, for example, getMinimumFractionDigits() returns a numerically greater value.

Authors
Mark Davis, Alan Liu
Since
1.1
External Specification
https://www.unicode.org/reports/tr35
See Also
Java Tutorial, NumberFormat, DecimalFormatSymbols, ParsePosition, Locale

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DecimalFormat.DigitArrays

The digit arrays used in the fast-path methods for collecting digits.

private static class
DecimalFormat.FastPathData

Helper inner utility class for storing the data used in the fast-path algorithm.

pack-priv static record
DecimalFormat.NumericPosition

NumericPosition is a helper record class that stores two indices of interest.

Field Summary

Modifier and TypeField and Description
private transient BigDecimal
private transient BigInteger
private static final char
CURRENCY_SIGN

The CURRENCY_SIGN is the standard Unicode symbol for currency.

pack-priv static final int
private boolean
decimalSeparatorAlwaysShown

If true, forces the decimal separator to always appear in a formatted number, even if the fractional part of the number is zero.

private transient DigitList
pack-priv static final int
pack-priv static final int
private static FieldPosition[]
private transient boolean
fastPathCheckNeeded

Flag stating need of check and reinit fast-path status on next format call.

private transient DecimalFormat.FastPathData
fastPathData

DecimalFormat reference to its FastPathData

private byte
groupingSize

The number of digits between grouping separators in the integer portion of a number.

private transient boolean
isCurrencyFormat

True if this object represents a currency format.

private transient boolean
isFastPath

The format fast-path status of the instance.

private static final double
MAX_INT_AS_DOUBLE

Maximum valid integer value for applying fast-path algorithm

pack-priv static final int
pack-priv static final int
private int
maximumFractionDigits

Hides java.text.NumberFormat.maximumFractionDigits.

The maximum number of digits allowed in the fractional portion of a BigInteger or BigDecimal number.
private int
maximumIntegerDigits

Hides java.text.NumberFormat.maximumIntegerDigits.

The maximum number of digits allowed in the integer portion of a BigInteger or BigDecimal number.
private byte
minExponentDigits

The minimum number of digits used to display the exponent when a number is formatted in exponential notation.

private int
minimumFractionDigits

Hides java.text.NumberFormat.minimumFractionDigits.

The minimum number of digits allowed in the fractional portion of a BigInteger or BigDecimal number.
private int
minimumIntegerDigits

Hides java.text.NumberFormat.minimumIntegerDigits.

The minimum number of digits allowed in the integer portion of a BigInteger or BigDecimal number.
private int
multiplier

The multiplier for use in percent, per mille, etc.

private String
negativePrefix

The symbol used as a prefix when formatting negative numbers, e.g. "-".

private transient FieldPosition[]
negativePrefixFieldPositions

FieldPositions describing the negative prefix String.

private String
negativeSuffix

The symbol used as a suffix when formatting negative numbers.

private transient FieldPosition[]
negativeSuffixFieldPositions

FieldPositions describing the negative suffix String.

private String
negPrefixPattern

The prefix pattern for negative numbers.

private String
negSuffixPattern

The suffix pattern for negative numbers.

private boolean
parseBigDecimal

If true, parse returns BigDecimal wherever possible.

private boolean
parseStrict

True if this DecimalFormat will parse numbers with strict leniency.

private static final char
private static final char
private static final String
private static final char
private static final char
private static final char
private static final char
private static final char
private static final char
private String
positivePrefix

The symbol used as a prefix when formatting positive numbers, e.g. "+".

private transient FieldPosition[]
positivePrefixFieldPositions

FieldPositions describing the positive prefix String.

private String
positiveSuffix

The symbol used as a suffix when formatting positive numbers.

private transient FieldPosition[]
positiveSuffixFieldPositions

FieldPositions describing the positive suffix String.

private String
posPrefixPattern

The prefix pattern for non-negative numbers.

private String
posSuffixPattern

The suffix pattern for non-negative numbers.

private static final char
private RoundingMode
roundingMode

The java.math.RoundingMode used in this DecimalFormat.

private int
serialVersionOnStream

Hides java.text.NumberFormat.serialVersionOnStream.

The internal serial version which says which version was written.
pack-priv static final long
private static final int
private static final int
private static final int
private DecimalFormatSymbols
symbols

The DecimalFormatSymbols object used by this format.

private boolean
useExponentialNotation

True to force the use of exponential (i.e. scientific) notation when formatting numbers.

Inherited from java.text.NumberFormat:
FRACTION_FIELDINTEGER_FIELD

Constructor Summary

AccessConstructor and Description
public
DecimalFormat()

Creates a DecimalFormat using the default pattern and symbols for the default FORMAT locale.

public
DecimalFormat(String
a non-localized pattern string.
pattern
)

Creates a DecimalFormat using the given pattern and the symbols for the default FORMAT locale.

public
DecimalFormat(String
a non-localized pattern string
pattern
,
DecimalFormatSymbols
the set of symbols to be used
symbols
)

Creates a DecimalFormat using the given pattern and symbols.

Method Summary

Modifier and TypeMethod and Description
private void
addAffixes(char[]
Char array container which to prepend/append the prefix/suffix.
container
,
char[]
Char sequence to prepend as a prefix.
prefix
,
char[]
Char sequence to append as a suffix.
suffix
)

Internal utility.

private void
append(Format.StringBuf result, String string, Format.FieldDelegate delegate, FieldPosition[] positions, Format.Field signAttribute)

Appends the String string to result.

private void
appendAffix(StringBuilder
the affix string is appended to this
buffer
,
String
a pattern such as posPrefixPattern; may be null
affixPattern
,
String
a corresponding expanded affix, such as positivePrefix. Ignored unless affixPattern is null. If affixPattern is null, then expAffix is appended as a literal affix.
expAffix
,
boolean
true if the appended pattern should contain localized pattern characters; otherwise, non-localized pattern chars are appended
localized
)

Appends an affix pattern to the given StringBuilder, quoting special characters as needed.

private void
appendAffix(StringBuilder buffer, String affix, boolean localized)

Append an affix to the given StringBuilder, using quotes if there are special characters.

private void
appendSuffix(char[]
The suffix characters to append to result.
suffix
,
int
The number of chars to append.
len
,
char[]
Char array container which to append the suffix
container
)

Appends the passed suffix chars to given result container.

public void
applyLocalizedPattern(String
a new pattern
pattern
)

Apply the given pattern to this Format object.

public void
applyPattern(String
a new pattern
pattern
)

Apply the given pattern to this Format object.

private void
applyPattern(String pattern, boolean localized)

Does the real work of applying a pattern.

private boolean
checkAndSetFastPathStatus()

Check validity of using fast-path for this instance.

public Object
clone()

Overrides java.text.NumberFormat.clone.

Standard override; no change in semantics.

private void
collectFractionalDigits(int
The int value from which we collect digits.
number
,
char[]
The char array container where digits are stored.
digitsBuffer
,
int
the position from which we start storing digits in digitsBuffer.
startIndex
)

Collects the 2 (currency) or 3 (decimal) fractional digits from passed number, starting at startIndex position inclusive.

private void
collectIntegralDigits(int
The int value from which we collect digits.
number
,
char[]
The char array container where digits and grouping chars are stored.
digitsBuffer
,
int
the position from which we start storing digits in digitsBuffer.
backwardIndex
)

Collects integral digits from passed number, while setting grouping chars as needed.

pack-priv Format.StringBuf
doubleSubformat(double number, Format.StringBuf result, Format.FieldDelegate delegate, boolean isNegative)

public boolean

Returns:

true if the specified object is equal to this DecimalFormat
equals
(Object
object to be compared for equality
obj
)

Overrides java.text.NumberFormat.equals.

Compares the specified object with this DecimalFormat for equality.

private boolean

Returns:

the decision that must be taken regarding half-even rounding.
exactRoundUp
(double
The fractional value on which we take rounding decision.
fractionalPart
,
int
The integral part of the scaled fractional value.
scaledFractionalPartAsInt
)

Returns true if rounding-up must be done on scaledFractionalPartAsInt, false otherwise.

private String

Returns:

the expanded equivalent of pattern
expandAffix
(String
the non-null, possibly empty pattern
pattern
,
StringBuilder
a scratch StringBuilder; its contents will be lost
buffer
)

Expand an affix pattern into an affix string.

private FieldPosition[]

Returns:

FieldPosition array of the resulting fields.
expandAffix
(String
the non-null, possibly empty pattern
pattern
)

Expand an affix pattern into an array of FieldPositions describing how the pattern would be expanded.

private void
expandAffixes()

Expand the affix pattern strings into the expanded affix strings.

private void
fastDoubleFormat(double
the double value to be formatted.
d
,
boolean
Flag precising if d is negative.
negative
)

This is the main entry point for the fast-path format algorithm.

pack-priv String

Returns:

the formatted result for d as a string.
fastFormat
(double
The double value to be formatted
d
)

Overrides java.text.NumberFormat.fastFormat.

A fast-path shortcut of format(double) to be called by NumberFormat, or by format(double, ...) public methods.

public final StringBuffer

Returns:

the value passed in as toAppendTo
format
(Object
the number to format
number
,
StringBuffer
the StringBuffer to which the formatted text is to be appended
toAppendTo
,
FieldPosition
keeps track on the position of the field within the returned string. For example, for formatting a number 1234567.89 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 9, respectively for the output string 1,234,567.89.
pos
)

Overrides java.text.NumberFormat.format.

Formats a number and appends the resulting text to the given string buffer.

pack-priv final Format.StringBuf
public StringBuffer

Returns:

The formatted number string
format
(double
The double to format
number
,
StringBuffer
where the text is to be appended
result
,
FieldPosition
keeps track on the position of the field within the returned string. For example, for formatting a number 1234567.89 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 9, respectively for the output string 1,234,567.89.
fieldPosition
)

Implements abstract java.text.NumberFormat.format.

Formats a double to produce a string.

pack-priv Format.StringBuf
format(double number, Format.StringBuf result, FieldPosition fieldPosition)

Overrides java.text.NumberFormat.format.

pack-priv Format.StringBuf

Returns:

The formatted number string
format
(double
The double to format
number
,
Format.StringBuf
where the text is to be appended
result
,
Format.FieldDelegate
notified of locations of sub fields
delegate
)

Formats a double to produce a string.

public StringBuffer

Returns:

The formatted number string
format
(long
The long to format
number
,
StringBuffer
where the text is to be appended
result
,
FieldPosition
keeps track on the position of the field within the returned string. For example, for formatting a number 123456789 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 11, respectively for the output string 123,456,789.
fieldPosition
)

Implements abstract java.text.NumberFormat.format.

Format a long to produce a string.

pack-priv Format.StringBuf
format(long number, Format.StringBuf result, FieldPosition fieldPosition)

Overrides java.text.NumberFormat.format.

pack-priv Format.StringBuf

Returns:

The formatted number string
format
(long
The long to format
number
,
Format.StringBuf
where the text is to be appended
result
,
Format.FieldDelegate
notified of locations of sub fields
delegate
)

Format a long to produce a string.

private Format.StringBuf

Returns:

The formatted number string
format
(BigDecimal
The BigDecimal to format
number
,
Format.StringBuf
where the text is to be appended
result
,
FieldPosition
keeps track on the position of the field within the returned string. For example, for formatting a number 1234567.89 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 9, respectively for the output string 1,234,567.89.
fieldPosition
)

Formats a BigDecimal to produce a string.

pack-priv Format.StringBuf

Returns:

The formatted number string
format
(BigDecimal
The BigDecimal to format
number
,
Format.StringBuf
where the text is to be appended
result
,
Format.FieldDelegate
notified of locations of sub fields
delegate
)

Formats a BigDecimal to produce a string.

private Format.StringBuf

Returns:

The formatted number string
format
(BigInteger
The BigInteger to format
number
,
Format.StringBuf
where the text is to be appended
result
,
FieldPosition
keeps track on the position of the field within the returned string. For example, for formatting a number 123456789 in Locale.US locale, if the given fieldPosition is NumberFormat#INTEGER_FIELD, the begin index and end index of fieldPosition will be set to 0 and 11, respectively for the output string 123,456,789.
fieldPosition
)

Format a BigInteger to produce a string.

pack-priv Format.StringBuf

Returns:

The formatted number string
format
(BigInteger
The BigInteger to format
number
,
Format.StringBuf
where the text is to be appended
result
,
Format.FieldDelegate
notified of locations of sub fields
delegate
,
boolean formatLong)

Format a BigInteger to produce a string.

public AttributedCharacterIterator

Returns:

AttributedCharacterIterator describing the formatted value.
formatToCharacterIterator
(Object
The object to format
obj
)

Overrides java.text.Format.formatToCharacterIterator.

Formats an Object producing an AttributedCharacterIterator.

private BigDecimal
getBigDecimalMultiplier()

Return a BigDecimal multiplier.

private BigInteger
getBigIntegerMultiplier()

Return a BigInteger multiplier.

public Currency

Returns:

the currency used by this decimal format, or null
getCurrency
()

Overrides java.text.NumberFormat.getCurrency.

Gets the currency used by this decimal format when formatting currency values.

public DecimalFormatSymbols

Returns:

a copy of the desired DecimalFormatSymbols
getDecimalFormatSymbols
()

Returns a copy of the decimal format symbols, which is generally not changed by the programmer or user.

pack-priv DigitList

Returns:

the DigitList used by this DecimalFormat instance
getDigitList
()

Returns the DigitList used by this DecimalFormat instance.

public int

Returns:

the grouping size
getGroupingSize
()

Return the grouping size.

public int
getMaximumFractionDigits()

Overrides java.text.NumberFormat.getMaximumFractionDigits.

Returns the maximum number of digits allowed in the fraction portion of a number during formatting.

public int
getMaximumIntegerDigits()

Overrides java.text.NumberFormat.getMaximumIntegerDigits.

Returns the maximum number of digits allowed in the integer portion of a number during formatting.

public int
getMinimumFractionDigits()

Overrides java.text.NumberFormat.getMinimumFractionDigits.

Returns the minimum number of digits allowed in the fraction portion of a number during formatting.

public int
getMinimumIntegerDigits()

Overrides java.text.NumberFormat.getMinimumIntegerDigits.

Returns the minimum number of digits allowed in the integer portion of a number during formatting.

public int

Returns:

the multiplier
getMultiplier
()

Gets the multiplier for use in percent, per mille, and similar formats.

public String

Returns:

the negative prefix
getNegativePrefix
()

Get the negative prefix.

private FieldPosition[]

Returns:

FieldPositions in positive prefix
getNegativePrefixFieldPositions
()

Returns the FieldPositions of the fields in the prefix used for negative numbers.

public String

Returns:

the negative suffix
getNegativeSuffix
()

Get the negative suffix.

private FieldPosition[]

Returns:

FieldPositions in positive prefix
getNegativeSuffixFieldPositions
()

Returns the FieldPositions of the fields in the suffix used for negative numbers.

public String

Returns:

the positive prefix
getPositivePrefix
()

Get the positive prefix.

private FieldPosition[]

Returns:

FieldPositions in positive prefix
getPositivePrefixFieldPositions
()

Returns the FieldPositions of the fields in the prefix used for positive numbers.

public String

Returns:

the positive suffix
getPositiveSuffix
()

Get the positive suffix.

private FieldPosition[]

Returns:

FieldPositions in positive prefix
getPositiveSuffixFieldPositions
()

Returns the FieldPositions of the fields in the suffix used for positive numbers.

public RoundingMode

Returns:

The RoundingMode used for this DecimalFormat.
getRoundingMode
()

Overrides java.text.NumberFormat.getRoundingMode.

Gets the java.math.RoundingMode used in this DecimalFormat.

private int
groupingViolationIndex(int pos, int prevGroupingPos)

pack-priv boolean

Returns:

true, if number is a Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY; false otherwise
handleInfinity
(double
the double number to format
number
,
Format.StringBuf
where the text is to be appended
result
,
Format.FieldDelegate
notified of locations of sub fields
delegate
,
boolean
whether the given number is negative
isNegative
)

Checks if the given number is Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY.

pack-priv boolean

Returns:

true, if number is a NaN; false otherwise
handleNaN
(double
the double number to format
number
,
Format.StringBuf
where the text is to be appended
result
,
Format.FieldDelegate
notified of locations of sub fields
delegate
)

Checks if the given number is Double.NaN.

public int

Returns:

the hash code for this DecimalFormat
hashCode
()

Overrides java.text.NumberFormat.hashCode.

Returns the hash code for this DecimalFormat.

public boolean

Returns:

true if the decimal separator is always shown; false otherwise
isDecimalSeparatorAlwaysShown
()

Allows you to get the behavior of the decimal separator with integers.

private boolean
isGroupingViolation(int pos, int prevGroupingPos)

public boolean

Returns:

true if the parse method returns BigDecimal; false otherwise
isParseBigDecimal
()

Returns whether the parse(java.lang.String, java.text.ParsePosition) method returns BigDecimal.

public boolean
isStrict()

Overrides java.text.NumberFormat.isStrict.

Returns true if this format will parse numbers strictly; false otherwise.

private void
localizeDigits(char[]
The char array container where the digits are stored.
digitsBuffer
)

Converts digit chars from digitsBuffer to current locale.

pack-priv boolean

Returns:

true if the text matches the affix
matchAffix
(String text, int position, String affix)

Returns true if the text matches the affix.

public Number

Returns:

the parsed value, or null if the parse fails
parse
(String
the string to be parsed
text
,
ParsePosition
A ParsePosition object with index and error index information as described above.
pos
)

Implements abstract java.text.NumberFormat.parse.

Parses text from the beginning of the given string to produce a Number.

private boolean
posEqualsNegPattern()

This method returns true if the positive and negative prefix/suffix values are equivalent.

private void
prependPrefix(char[]
The prefix characters to prepend to result.
prefix
,
int
The number of chars to prepend.
len
,
char[]
Char array container which to prepend the prefix
container
)

Prepends the passed prefix chars to given result container.

private void
readObject(ObjectInputStream stream)

Hides java.text.NumberFormat.readObject.

Reads the default serializable fields from the stream and performs validations and adjustments for older serialized versions.

private void
resetFastPathData(boolean fastPathWasOn)

public void
setCurrency(Currency
the new currency to be used by this decimal format
currency
)

Overrides java.text.NumberFormat.setCurrency.

Sets the currency used by this number format when formatting currency values.

public void
setDecimalFormatSymbols(DecimalFormatSymbols
desired DecimalFormatSymbols
newSymbols
)

Sets the decimal format symbols, which is generally not changed by the programmer or user.

public void
setDecimalSeparatorAlwaysShown(boolean
true if the decimal separator is always shown; false otherwise
newValue
)

Allows you to set the behavior of the decimal separator with integers.

pack-priv void
setDigitList(Number
the number to format
number
,
boolean
true, if the number is negative; false otherwise
isNegative
,
int
the max digits
maxDigits
)

Utility method that sets the DigitList used by this DecimalFormat instance.

public void
setGroupingSize(int
the new grouping size
newValue
)

Set the grouping size.

public void
setGroupingUsed(boolean newValue)

Overrides java.text.NumberFormat.setGroupingUsed.

Set whether or not grouping will be used in this format.

public void
setMaximumFractionDigits(int
the maximum number of fraction digits to be shown.
newValue
)

Overrides java.text.NumberFormat.setMaximumFractionDigits.

Sets the maximum number of digits allowed in the fraction portion of a number during formatting.

public void
setMaximumIntegerDigits(int
the maximum number of integer digits to be shown.
newValue
)

Overrides java.text.NumberFormat.setMaximumIntegerDigits.

Sets the maximum number of digits allowed in the integer portion of a number during formatting.

public void
setMinimumFractionDigits(int
the minimum number of fraction digits to be shown.
newValue
)

Overrides java.text.NumberFormat.setMinimumFractionDigits.

Sets the minimum number of digits allowed in the fraction portion of a number during formatting.

public void
setMinimumIntegerDigits(int
the minimum number of integer digits to be shown.
newValue
)

Overrides java.text.NumberFormat.setMinimumIntegerDigits.

Sets the minimum number of digits allowed in the integer portion of a number during formatting.

public void
setMultiplier(int
the new multiplier
newValue
)

Sets the multiplier for use in percent, per mille, and similar formats.

public void
setNegativePrefix(String
the new negative prefix. Non-null.
newValue
)

Set the negative prefix.

public void
setNegativeSuffix(String
the new negative suffix. Non-null.
newValue
)

Set the negative suffix.

public void
setParseBigDecimal(boolean
true if the parse method returns BigDecimal; false otherwise
newValue
)

Sets whether the parse(java.lang.String, java.text.ParsePosition) method returns BigDecimal.

public void
setPositivePrefix(String
the new positive prefix. Non-null.
newValue
)

Set the positive prefix.

public void
setPositiveSuffix(String
the new positive suffix. Non-null.
newValue
)

Set the positive suffix.

public void
setRoundingMode(RoundingMode
The RoundingMode to be used
roundingMode
)

Overrides java.text.NumberFormat.setRoundingMode.

Sets the java.math.RoundingMode used in this DecimalFormat.

public void
setStrict(boolean strict)

Overrides java.text.NumberFormat.setStrict.

Change the leniency value for parsing.

private int
shiftDecimalAt(int decimalAt, long exponent)

private Format.StringBuf
subformat(Format.StringBuf result, Format.FieldDelegate delegate, boolean isNegative, boolean isInteger, int maxIntDigits, int minIntDigits, int maxFraDigits, int minFraDigits)

Complete the formatting of a finite number.

pack-priv void
subformatNumber(Format.StringBuf
where the text is to be appended
result
,
Format.FieldDelegate
notified of the location of sub fields
delegate
,
boolean
true, if the number is negative; false otherwise
isNegative
,
boolean
true, if the number is an integer; false otherwise
isInteger
,
int
maximum integer digits
maxIntDigits
,
int
minimum integer digits
minIntDigits
,
int
maximum fraction digits
maxFraDigits
,
int
minimum fraction digits
minFraDigits
)

Subformats number part using the DigitList of this DecimalFormat instance.

private final boolean
subparse(String
The string to parse.
text
,
ParsePosition
The position at which to being parsing. Upon return, the first unparseable character.
parsePosition
,
String positivePrefix, String negativePrefix, DigitList
The DigitList to set to the parsed value.
digits
,
boolean
If true, parse an exponent. This means no infinite values and integer only.
isExponent
,
boolean[]
Upon return contains boolean status flags indicating whether the value was infinite and whether it was positive.
status
)

Parse the given text into a number.

pack-priv DecimalFormat.NumericPosition

Returns:

returns a NumericPosition that stores both a full traversal index, and an int only index.
subparseNumber
(String
the string to parse
text
,
int
the position at which parsing begins
position
,
DigitList
the DigitList to set to the parsed value
digits
,
boolean
whether to check for exponential number
checkExponent
,
boolean
if the exponential part is encountered
isExponent
,
boolean[]
upon return contains boolean status flags indicating whether the value is infinite and whether it is positive
status
)

Parses a number from the given text.

public String

Returns:

a localized pattern string
toLocalizedPattern
()

Synthesizes a localized pattern string that represents the current state of this Format object.

public String

Returns:

a pattern string
toPattern
()

Synthesizes a pattern string that represents the current state of this Format object.

private String
toPattern(boolean localized)

Implementation of producing a pattern.

public String

Returns:

a string identifying this DecimalFormat, for debugging
toString
()

Overrides java.lang.Object.toString.

Returns a string identifying this DecimalFormat, for debugging.

Inherited from java.text.NumberFormat:
formatformatgetAvailableLocalesgetCompactNumberInstancegetCompactNumberInstancegetCurrencyInstancegetCurrencyInstancegetInstancegetInstancegetIntegerInstancegetIntegerInstancegetNumberInstancegetNumberInstancegetPercentInstancegetPercentInstancegetScientificInstancegetScientificInstanceisGroupingUsedisParseIntegerOnlymatchToStyleparseparseObjectsetParseIntegerOnly