The formatting patterns presented here are used for
They are based on the formatting patterns used in many modern programming languages (for example the Java classes “DecimalFormat” and “SimpleDateFormat”).
Formatting numbers is sometimes necessary to present the values in a uniform fashion. Take for example the following value set:
12 123.4567 145 1.07 15.009 .95In order to harmonize the format of these values you can either make changes to the source data or use a number formatting pattern.
For example if you wanted to display all values with two decimal digits and at least one digit to the left of the decimal point you would write:
"##0.00"
The formatted numbers would be displayed like this:
12.00 123.46 145.00 1.07 15.01 0.95
The table below lists the formatting pattern elements available.
Format strings for numbers
Symbol | Description |
---|---|
0 | Represents a number. If the digit is empty a zero will be displayed/printed. |
# | Represents a number. If the digit is empty nothing will be displayed/printed. This is useful for skipping leading zeros or trailing decimal digits |
. | Decimal separator. Separates the left from the right part of the decimal number. |
, | Grouping of numbers. Usually for the thousands separator as in “1,000,000.00”. |
; | Grouping symbol for positive/negative values. The pattern for positive numbers is on the left of the semicolon and the pattern for negative numbers on the right. |
- | Prefix for negative numbers |
% | Percent pattern. The number will be multiplied by 100 and displayed as a percent value |
‰ | Per-thousand pattern. The number will be multiplied by 1000 and displayed as one-tenth of a percent value |
any other character | All other characters will not be evaluated and are displayed as-is. |
Examples for number formatting patterns
Formatting string | Input number | Resulting output |
---|---|---|
0000 | 28 | 0028 |
0000 | 28.45 | 0028 |
0000 | 12000100 | 12000100 |
## | 28 | 28 |
## | 28.4599 | 28 |
## | 12000100 | 12000100 |
.00 | 28.4501 | 28.45 |
.00 | .3456 | .35 |
0.00 | .446 | 0.45 |
#.00000 | 28.45 | 28.45000 |
,### | 12000100.456 | 12,000,100 |
#.#;(#.#) | 28.45 | 28.5 |
#.#;(#.#) | -28.45 | (28.5) |
#.# USD | 28.45 | 28.5 USD |
Internally a date value is stored in milliseconds since midnight 01 January, 1970 UTC. In order to display something more meaningful than 'today is 834234543213456765 o'clock' you have to specify what the output should look like.
A formatting pattern of
"EEEE MMM d'th' h':'m 'o'' clock'"for example, would result in the following output:
Monday Jun 7th 10:31 o'clock
Format-strings for date values
Symbol | Description | Output |
---|---|---|
G | Era | AD |
yy | Year. Two digits | 11 |
yyyy | Year. Four digits | 2011 |
M | Month in Year | 8 |
MM | Month in year two digits | 08 |
MMM | Month in abbreviated form | Sep |
MMMM | Month in complete length | September |
d | Day of the month | 31 |
h | Hour (1-12) | 11 |
H | Hour (0-23) | 15 |
m | Minute | 55 |
s | Second | 37 |
S | Millisecond | 998 |
E | Weekday abbreviated form | Mo |
EEEE | Weekday in complete length | Monday |
' | Additional text must be enclosed in single quotes | hh 'hours later ' → 12 hours later |
' ' | To display one single quote | hh 'o''clock' -> 12 o'clock |
A category value is stored as a string. By default all characters of the string are displayed if there is enough space. In most cases there is not enough space to show all x-axis labels in full length since the x-axis has a rather limited amount of space available. In this case a rather complex logic for “thinning out” values is applied to the x-axis which involves a reduction of the number of tickmarks but also a reduction in length of each individual tickmark text.
In order to enforce the display of a specific number of characters, the following formatting patterns can be applied. The number of hashmarks (”#”) determines the number of characters displayed. The ”<” or ”>” sign determines if the first or last n characters are used.
A formatting pattern of
"<###"
applied to the string “January” for example would result in an output like: Jan
A formatting pattern of
"###>"
applied to the string “January” would result in an output like: ary
Formatting strings for category values on the X-Axis
Formatting string | Input number | Resulting output |
---|---|---|
* | January | January |
<### | January | Jan |
########> | 10-Jan-2011 | Jan-2011 |