How to implement custom functions for currency formatting and for rounding off.

0

Hi,

How to implement custom functions for currency formating in Big decimal values. 

yashaswiniverma397's picture
Joined: Nov 7 2019 - 5:38am
Last seen: 10 hours 31 min ago

3 Answers:

1

You can use any expression for the pattern.. either a fix one or also a pattern-expression that could be dynamic.

With a small scriplet or a static ToolsClass you can even create something like this as a static method call:

YourSpecialCurrencyFormatter.getPatternByAnySpecialCondition(...)

that just returns a String for the currency pattern. (e.g to include some static string into the pattern like this "###,##0.## €")

Also the textfield (expression) itself can so changed dynamically depending on some other fields/variables/parameters or whatever, without using the textfield pattern.

hth + regards

C-Box

C-Box's picture
2122
Joined: Jul 19 2006 - 5:58pm
Last seen: 1 day 7 hours ago
0

Thankyou C-BOX, :)

What if we have 2-3 currency formats, How can we set a patterns for each of them differently? 

for example : for example we have Japeneese Yen, decimal places = 0,

                                                                    Euro - cents decimal places = 2.

 

yashaswiniverma397's picture
Joined: Nov 7 2019 - 5:38am
Last seen: 10 hours 31 min ago
0

Well it depends where your get the information from... so from a global parameter at report runtime or from a field at record level....

So my first idea would be to make your FormatterTools doing the work (just pseudocode here:)

/**
 * returns just a pattern depending on the currency 
 */
 
public static String getPatternByAnySpecialCondition(String yourCurrency){
 
    if ("€".equals(yourCurrency)){ 
      return "###,###.## €"; // Euro
    } else if ("¥".equals(yourCurrency)){
      return "###,### ¥"; // Japanese
    else{
      return "###,###.## "; // Default
    }
}

and at your Pattern Expression you can call that method e.g.

YourSpecialCurrencyFormatter.getPatternByAnySpecialCondition($P{YourGlobalCurrencySymbolSetAtReportLevel})

or at field level

YourSpecialCurrencyFormatter.getPatternByAnySpecialCondition($F{YourCurrencyFromAFieldInResultSetOfCurrentRecord})

of course you could also create a method to convert your whole BigDecimal field according to correct symbols and currency as well using the correct locale and so on ( http://tutorials.jenkov.com/java-internationalization/decimalformat.html ) ... so just give it a try what fits best your needs.

hth + regards

C-Box

C-Box's picture
2122
Joined: Jul 19 2006 - 5:58pm
Last seen: 1 day 7 hours ago
Feedback
randomness