Introduction
By default, at the ad hoc design level, values get displayed "as is" without any formatting. JasperReports Server comes with a set of pre-defined formatting options that you can apply to columns on a report, but what do you do if you want to enable other options? In this article, we look into adding more currency for numeric values.
Out-of-the-box functionality
When using the ad hoc report designer, numeric values get displayed "as is" in the designer, such as in the screen shot below
In this article, we consider formatting numeric values, and we take a closer look at formatting for currency symbols. The method we'll take a look applies to other situations as well.
We can change the formatting for numeric values by right-clicking on the column we're interested in, and then choosing the style we want, as in the screen shot below:
Then we can go ahead and choose the currency format we want, and we would get a result as in the screen shot below
However, the list of choices is limited, and so the question becomes how do we add more choices to that list?
Understanding the configuration file
You can manage the formatting options for numeric values by editing the adhoc_masks.properties file, which you can find under the web application root in the /jasperserver-pro/WEB-INF/bundles directory.
Let's focus on adding more formatting options for decimal values. We find the section below in the file:
ADH_100_MASK_dec_0 = #,##0.00 ADH_100_MASK_dec_1 = 0 ADH_100_MASK_dec_2 = $#,##0.00;($#,##0.00) ADH_100_MASK_dec_3 = $#,##0;($#,##0) ADH_100_MASK_dec_4 = EUR #,##0;(EUR #,##0) ADH_100_MASK_dec_5 = u20AC #,##0;(u20AC #,##0)
The first four entries correspond to what's available by default in JasperReports Server. I added the last two entries to display "EUR" before a value (the ISO code for the euro) and the € symbol itself; u20AC is the Unicode value for the euro. Using the € symbol itself may or not work with your environment, and using the Unicode value itself insures that you won't encounter character set issues.
After modifying that file and restarting the server, you can go ahead and test the formatting options for ad hoc decimal values - first we see that there are extra values now available from which to choose:
And by choosing the format we're interested in, we see that we can mix currency symbols as in the screenshot below
Other Currency Codes
Here's a table with some common currency codes:
Currency | Unicode Value |
---|---|
British Pound (£) | u00A3 |
Japanese Yen (¥) | u00A5 |
Euro (€) | u20AC |
Indian Rupee | u20A8 |
Chinese Yuan | u3350 |
Recommended Comments
There are no comments to display.