Dynamic Numeric Pattern Formatting

Is it possible to dynamically change the pattern used for formatting numbers? 

In my scenario, we are batch printing many invoices at once.  The numeric formatting is based on the location of the recipient of the each invoice.  This location is part of the result set of data.  If Invoice #1 is from US then the format should have standard US formatting with the period used from decimal place and comma for digit grouping (#,##0.00).  However, if Invoice #2, in the same batch, has a Location of EU, then the format should change to a comma for decimal place and a period for digit grouping (#.##0,00).  I can't change the Locale because the pattern could change based on the Location of the recipient.  Any assistance would be appreciated.     

greg.sears's picture
Joined: Feb 24 2022 - 11:00am
Last seen: 1 week 1 day ago

Thank you for posting to the Jaspersoft Community. Our team of experts has read your question and we are working to get you an answer as quickly as we can. If you have a Jaspersoft Professional Subscription plan, please visit https://support.tibco.com/s/ for direct access to our technical support teams offering guaranteed response times.
 

mrajkuma - 3 months 2 weeks ago

2 Answers:

Hello,


It looks like without changing locale,  it's difficult to  dynamically change the pattern used for formatting numbers.
We found similar below community article where similar situation was encountered.

https://community.jaspersoft.com/questions/518137/dynamic-double-pattern

Might be this article help you however, we request you to log a feature request for your idea.

jphadtar's picture
1532
Joined: Mar 20 2022 - 10:51pm
Last seen: 14 hours 35 min ago

I was able to solve as follows:

String.format(new java.util.Locale($V{Locale}), "%.2f",$F{INVOICEAMOUNT} )

I can pass the Locale from the DB query and it will change along with the appropriate record.

greg.sears's picture
Joined: Feb 24 2022 - 11:00am
Last seen: 1 week 1 day ago
Feedback
randomness