The following section describes the format of the number used in the Java Programming Language. This format can be used for attributes of Number type – see Setting Properties of Number Attributes.
The string representing the number format has the following form:
positive-pattern[;negative-pattern]
If the negative pattern is omitted, negative numbers are formatted using the positive pattern with a “-“ character prepended to the result. Each pattern has the following form:
[prefix]integer[.fraction][suffix]
The following symbols are significant in the pattern string.
| Symbol | Description |
|---|---|
| 0 | A digit |
| # | A digit where 0 is not shown |
| . | A placeholder for a decimal separator |
| , | A placeholder for a grouping separator |
| ; | The format separator |
| - | The default negative prefix |
| % | Multiplies value by 100 and shows as a percentage |
Any characters other than these special characters can appear in the prefix or the suffix. A single quote can be used to escape a special character, if you need to use one of these symbols in a prefix or a suffix.
For example, the pattern string for U.S. currency values is:
$#,##0.00;($#,##0.00)
This indicates that a $ character is prepended to all formatted values. The grouping separator character , is inserted every three digits. Exactly two digits after the decimal place are always shown. Negative values are shown in parentheses. Thus, the value -1234.56 produces output like:
($1,234.56)