문제

How can I override the language specific pattern in iReport? I have set the pattern #,##0.00 on a field with a Double value.

If the report is in english, I get the following example output.:

10,000.00

If the report is in german, I get the following example output.:

10.000,00

I need the output 10.000,00 for the english and the german report.

How can I realize that?

도움이 되었습니까?

해결책

Do not set any pattern (make sure to remove it). Instead, in the TextFieldExpression field use

new java.text.DecimalFormat("#,##0.00", new java.text.DecimalFormatSymbols(java.util.Locale.GERMANY)).format($P{parameter1}).

(This is a string. If your textfield expression class is double, you can parse the result.) This will format the number as in German locale for all languages.

다른 팁

The latest versions of iReport has a feature called Pattern Expression. In that you only need to specify a pattern string, and leave the rest of the field calculation the same. This way you can separate the data from the format, I think it keeps things cleaner, but it also gives you more control over the format at runtime.

Edit. An example was asked for, here it is: https://gist.github.com/ilopez/9369809#file-so22141769-jrxml

The magic happens in this expression:

new DecimalFormat().toPattern()

Report Using Local Locale Settings

You can specify report locale via the REPORT_LOCALE parameter see: Setting REPORT_LOCALE in IReport?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top