Hi,
How to implement custom functions for currency formating in Big decimal values.
3 Answers:
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
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