| Pattern Characters | Parsing |
| Forcing + | Learning More |
| Handling Negatives | Links |
| Post-Processing |
| Most Common DecimalFormat Pattern Characters | |
|---|---|
| Char | Meaning |
| 0 | digit or lead zeroes |
| # | digit or nothing at all. There is no pattern character to provide lead spaces for creating a fixed length pattern. |
| . | decimal point. Actual character displayed is locale-specific, though the character you specify for the pattern is always a dot. e.g. in Sweden this will display as a comma. |
| , | comma for grouping digits. Actual character displayed is locale-specific, though the character you specify for the pattern is always a docomma. e.g. in Sweden this will display as a period. |
| E | exponent separator. |
| ' | used to surround decorative characters, including embedded spaces. e.g. "'$'###,##0.00" |
| ; | Used to separate the pattern for positive numbers from the pattern for negative numbers. |
| % | display a ratio as a percentage. As in "##0.0%", multiplies the displayed value by 100 and displays a decorative trailing %. |
// Getting an explicit + - sign // Formats 3.0 as "+3.0" and -3.0 as "-3.0". // The surrounding ' are not needed in this case. DecimalFormat explicitSign = new DecimalFormat( "'+'0.0;'-'0.0" );
You can say something like this to arrange for negative numbers to be shown in parentheses:
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.16] | The information on this page is for non-military use only. | ||
| You are visitor number 20,113. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/Mindprod website mirror) | ||
| http://mindprod.com/jgloss/decimalformat.html | J:\mindprod\jgloss\decimalformat.html | ||