Name
DecimalFormat
Synopsis
This is the concrete
Format
class used by
NumberFormat
for all locales that use base 10
numbers. Most applications do not need to use this class directly;
they can use the static methods of NumberFormat
to
obtain a default NumberFormat
object for a desired
locale and then perform minor locale-independent customizations on
that object.
Applications that require highly customized number formatting and
parsing may create custom DecimalFormat
objects by
passing a suitable pattern to the DecimalFormat( )
constructor method. The
applyPattern( )
method can change this pattern. A pattern consists of a string of
characters from the table below. For example:
"$#,##0.00;($#,##0.00)"
Character |
Meaning |
---|---|
|
A digit; zeros show as absent. |
|
A digit; zeros show as 0. |
. |
The locale-specific decimal separator. |
, |
The locale-specific grouping separator (comma). |
|
The locale-specific negative prefix. |
|
Shows value as a percentage. |
|
Separates positive number format (on left) from optiona negative number format (on right). |
' |
Quotes a reserved character, so it appears literally in the output (apostrophe). |
other |
Appears literally in output. |
A DecimalFormatSymbols
object can be specified
optionally when creating a DecimalFormat
object.
If one is not specified, a DecimalFormatSymbols
object suitable for the default locale is used.
In Java 5.0, DecimalFormat
can return
java.math.BigDecimal
values from its
parse( )
method. Call setParseBigDecimal(
)
to ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.