Override language specific pattern in iReport - jasper-reports

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()
You can specify report locale via the REPORT_LOCALE parameter see: Setting REPORT_LOCALE in IReport?

Related

Change the date format for the showLastUpdateTime at the bottom of pages

I've added the
showLastUpdateTime: true,
line to my docusaurus.config.js, and the date is showing at the bottom of documents, but the format is US (which doesn't work for the majority of the world). I need it to be unambiguous, or not 'wrong' :D
Does anyone know how I can change this?
I don't believe you can explicitly set the format manually - it uses the default Intl.DateTimeFormat constructor under the hood - however you can manipulate it by setting the base locale of your site to something other than the default.
To do this, you need to leverage the i18n configuration - add this to your docusaurus.config.js:
i18n: {
defaultLocale: 'en-GB',
locales: ['en-GB']
}
Substitute en-GB for whatever your desired locale is, and you'll see the date show in that locale's format, so in the UK it's dd/MM/yyyy.

How to prevent writing before prefix in GWT valuebox

I am using GWT ValeBox with GWT Renderer to show amount with $ as prefix.
Now I want not to allow user to type any thing before dollar sign. I tried various GWT event handlers like ValueChangeHandler and some others but unable to achieve goal.
Still struggling for it. If anybody know good solution for it, please share here.
Regards,
The easiest would be to not include the currency as part of the value, but next to the field.
Alternatively, you could replace the value with a numeric-only value on focus, and reformat it as a currency on blur.
Couple of solutions:
Use a label before the valuebox. Label value will be $ and valuebox will contain the numeric value.
You can use empty text in the valuebox. Empty text will specify user to enter $ value.

IReport BigDecimal format "R$ #,##0.00" Monetary Value in Charts

I have a JasperReports chart, In the report, the field $F{soma} is BigDecimal, at thedatabase MySQL is Decimal(19,2). I'm using this sql: select SUM(valor) as soma to get the field $F{soma}.
Printing just $F{soma} i get labels like : 1.500,20. Without format expression. What i need is to show labels like : "R$ 1,520.20".
Tried this:
new java.text.DecimalFormat("R$ #,##0.00").format(Double.valueOf($F{soma}))
But no success, so if someone can point me a direction, i'll be thankful.
Have not reputation to post images, but links bellow are about the field types..
Field in MySQL:
Labels being printed (without format expression)
If your $F{soma} is a BigDecimal field then just write
new java.text.DecimalFormat("R$ #,##0.00").format($F{soma});
Use an instance of NumberFormat that has the right Currency to format the value. If the default Locale is giving you a problem,
Use NumberFormat.getCurrencyInstance(Locale inLocale) with the Locale you want, e.g.:
NumberFormat.getCurrencyInstance(Locale.US);
Use NumberFormat.getInstance() and setCurrency() to set the Currency you want, e.g.:
NumberFormat f = NumberFormat.getCurrencyInstance();
f.setCurrency(Currency.getInstance(…));

Formatting a string in jaspersoft?

In my report I have a string field with some numeric value, for example 123102,6. I would like to display 123 102,60 in my report.
Formatting numbers is a bugger in Java in general but gets even trickier with Jasper.
If your report works with a Locale that provides the space as the number group separator (like, for example, Locale.FRANCE does), then all you need to do is specify #,##0.00 as the value of the Pattern property of your field.
If that is not the case, or you are using several Locales, or you are resolving them at runtime, then the simplest way to solve your problem is to provide this:
new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.FRANCE))
.format(Double.valueOf($F{your_field_name}))
as the value of the Text Field Expression property of your field.

Jasper Reports: How to conditionally set the textbox style?

Is it possible in Jasper Reports to conditionally set a textbox style? If yes, how?
Please note that I'm aware of conditional styles, but I do not need a style which varies on a condition, but set the proper style using a different condition for each textbox (of course I could create a conditional style for each textbox, but that would be a real PITA...).
I'm using Jasper Reports 3.7.6 and the Jasper Studio Eclipse plugin.
Thanks
Use case example pseudocode:
bean1 {
f1
f2
}
bean2 {
cond1
cond2
}
<textbox1 style="(bean2.cond1 ? style1 : style2)">
bean1.f1
</textbox1>
<textbox2 style="(bean2.cond2 ? style1 : style2)">
bean1.f2
</textbox2>
Unfortunately you can't define a generic style. See page 135 of the iReport Ultimate Guide:
http://community.jaspersoft.com/documentation/ireport-ultimate-guide:
Please note that the conditions cannot be generic,
for instance, you cannot set a condition like “if the number is positive” or “if the string is
null
.” You must be very specific,
specifying, for example, that a
particular value (field, parameter, variable or
any expression involving them) must be positive
or
null, and so on.
Answering myself: it turns out that it is not possible to set conditional style the way I needed. I ended up with duplicating each text fields (a copy for each style), then setting the visibility upon the condition. Boring and time consuming, but it works.