| 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. It also works to the right of the decimal point. It also suppresses the decimal point to the left if there is no fractional part. |
| . | 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:
|
|
You can get the freshest copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) |
| http://mindprod.com/jgloss/decimalformat.html | J:\mindprod\jgloss\decimalformat.html | |
![]() | Please email your feedback for publication,
letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording,
broken/redirected link reports, suggestions to improve this page or comments to
Roedy Green :
| |
| Canadian Mind Products | ||
| mindprod.com IP:[65.110.21.43] | ||
| view Blog | Your face IP:[38.107.179.211] | |
| Feedback | You are visitor number 61,955. | |