Jump to content
We've recently updated our Privacy Statement, available here ×
  • Adding Currency Formatting Options to Ad Hoc


    gdmoreno
    • Features: Ad Hoc Product: JasperReports® Server

    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

    Formatting1.png.00d21cb4bc1773ca0cc8918963d1d219.png

    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:

    Formatting2.png.deb52df02bb30d099a91529886741d5a.png

    Then we can go ahead and choose the currency format we want, and we would get a result as in the screen shot below

    Formatting3.png.e3b0aa3a86eb440c81c38154b389b8e7.png

    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:

    Formatting4.png.79978fa245726ac1c1a762179a92cc20.png

    And by choosing the format we're interested in, we see that we can mix currency symbols as in the screenshot below

    Formatting5.png.fe0919990913a168d4a177515ef54992.png

    Other Currency Codes

    Here's a table with some common currency codes:

    CurrencyUnicode Value
    British Pound (£)u00A3
    Japanese Yen (¥)u00A5
    Euro (€)u20AC
    Indian Rupeeu20A8
    Chinese Yuanu3350

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...