Home

DecimalFormat

DecimalFormat is a concrete subclass of NumberFormat used to format decimal numbers according to a pattern, with awareness of locale-specific symbols. It is part of the java.text package in the Java standard library. A DecimalFormat instance formats numbers to produce human‑readable strings and can also parse strings back into numbers.

Pattern syntax lies at the core of DecimalFormat. The pattern uses 0 as a required digit and

DecimalFormat relies on DecimalFormatSymbols to provide locale‑specific symbols such as the decimal separator, grouping separator, percent

Thread safety is not guaranteed; instances should be confined to a single thread or protected by synchronization.

#
as
an
optional
digit.
The
decimal
separator
is
a
dot
in
the
pattern,
and
the
grouping
separator
is
a
comma.
A
semicolon
can
separate
positive
and
negative
subpatterns.
Exponent
notation
can
be
requested
with
E
or
e.
Percent
and
per‑mille
symbols
scale
the
number
by
100
or
1/1000,
respectively.
Text
can
be
included
literally
by
enclosing
it
in
single
quotes.
Patterns
may
be
customized
with
literals
and
multiple
sections,
and
can
be
supplied
to
the
constructor
or
set
via
methods.
sign,
and
currency
sign.
It
supports
various
configuration
options,
including
setMinimumFractionDigits,
setMaximumFractionDigits,
setMinimumIntegerDigits,
and
setGroupingUsed.
It
also
offers
setGroupingSize
for
grouping
behavior.
For
parsing,
parse
can
return
a
Number,
and
setParseBigDecimal(true)
makes
parsing
yield
a
BigDecimal.
Formatting
and
parsing
respect
the
locale
unless
overridden.
Related
classes
include
DecimalFormatSymbols
and
NumberFormat.