Jump to content

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


yashaswiniverma397

Recommended Posts

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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(...) [/code]

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

Link to comment
Share on other sites

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    }}[/code]

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

YourSpecialCurrencyFormatter.getPatternByAnySpecialCondition($P{YourGlobalCurrencySymbolSetAtReportLevel})[/code]

or at field level

YourSpecialCurrencyFormatter.getPatternByAnySpecialCondition($F{YourCurrencyFromAFieldInResultSetOfCurrentRecord})[/code]

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...