Formatting numeric data
You can display numeric data in a variety of formats. For example, you can display numbers with decimal values, in scientific notation, or with a currency symbol. By default, reports display numeric data according to the locale configured on the user’s machine. For example, a number that appears as 5015.75 in the English (United States) locale appears as 5015,75 in the French (France) locale. If you want some numeric data always to appear in a specific locale’s format, set the locale for that data element.
You can apply number formats only to decimal, float, or integer data types. Number formats have no effect on numbers that are string type. For example, a Customer_ID field can be defined as string type and display number values, such as 325. Number formats have no effect on these values.
Display numeric data using either a text element or a data element, depending on what you want to accomplish. When you drag a data set field from Data Explorer and drop it on the report page in the layout editor, BIRT Report Designer creates a data element to display the values of the data set field. The procedure for formatting data differs for a data element and a text element, as described in the following sections.
Formatting numeric data in a data element
Specify the format of numeric data in a data element by setting the data element’s Format Number property, as shown in Figure 8‑3.
Figure 8‑3 Format Number property values
Choose a format and, optionally, a locale. Use the locale’s Auto value to display the data according to the locale set on the user’s machine.
Table 8‑1 lists the available number formats and provides examples of how the formatted data appears. The examples in the table reflect the English (United States) locale. If you select a different locale, the data appears differently. When selecting a number format, you can set additional formatting options, such as the number of decimal places, the inclusion of a thousands separator, a currency symbol, and so on.
Table 8‑1 Examples of number formats
Format type
Example of data display
General Number
3200 or 3200.5 or 3200.75, depending on the original value. Whole numbers and numbers with up to three decimal places appear in their original format.
Currency
$3,200.50 or ¥3200 or 3,200€, depending on the symbol, symbol position, decimal place, and thousands separator values you set.
Fixed
3200 or 3200.5 or 3,200.48, depending on the decimal place and thousands separator values you set.
Percent
65% or 65.7% or %65, depending on the symbol position and decimal place values that you set. This format multiplies the original value by 100 and adds the percent (%) symbol.
Scientific
3.20E03 or 3E03, depending on the decimal place value you set.
You can also define your own formats. For example, you can specify the number of digits after the decimal or add literal characters to the numbers. To define a custom format, you use special symbols to construct a format pattern. BIRT Report Designer supports the Java numeric formatting defined by the DecimalFormat class. For details about the supported formatting symbols, see the Javadoc for DecimalFormat.
Table 8‑2 shows examples of custom format patterns and their effects on numeric data displayed in the English (United States) locale.
Table 8‑2 Results of custom number format patterns
Format pattern
Data in the data set
Result
0000.00
12.5
124.5
1240.553
0012.50
0124.50
1240.55
#.000
100
100.25
100.2567
100.000
100.250
100.257
$#,###
2000.00
20000.00
$2,000
$20,000
ID #
15
ID 15
Formatting numeric data in a text element
To insert dynamic data in a text element, use the VALUE-OF tag. To format the dynamic data, include a format attribute that specifies the format, as shown in the following examples. You must enclose the format value in double quotation marks (" ").
<VALUE-OF format="$#,###.00">row["orderTotal"]</VALUE-OF>
<VALUE-OF format="#.000">row["unitTotal"]</VALUE-OF>
You can use any format pattern that the Format Number property supports, as described in the preceding section.