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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access