I am using Jasper Reports 6.0.1 with Jaspersoft Studio.
I have a report with a subreport. The subreport correctly gets the data set from the main report, with values: - string - double
I have problems with correctly displaying the double values in the report. So the Json contains values like:
'doubleValue': '0.431'
The field 'doubleValue' is correctly defined in the subreport:
<field name="doubleValue" class="java.lang.Double">
<fieldDescription><![CDATA[doubleValue]]></fieldDescription>
</field>
And the 'doubleValue' seems correctly used in the report:
<textField pattern="#0.00">
<reportElement x="690" y="0" width="75" height="30" uuid="d265ebec-6fa7-421e-8d58-c7f2d32eea6b">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<box>
<topPen lineWidth="0.1"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<font size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{doubleValue}]]></textFieldExpression>
</textField>
The doubleValue seems to be correctly formatted in the output: '3.00'
BUT: the source of the field value was 3.41. So I have inspected the values deeply, and all values are formatted as 'x.00' no matter what is behind the decimal separator.
Please help me, what am I doing wrong?
I need the data correctly exported to XLSX (so it knows there is a number in the cell), and I am using the following option for this:
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
These problem's often occurs when decimal separator changes on the basis of localization es. .(dot) is decimal separator in the US but in Italy the decimal separator is , (comma)
However jasper report (v 6) should handle this without problem, your pattern should be in US format and jasper report will export in Locale.getDefault()
format (also applying correct pattern in excel).
So there should be nothing wrong with your jrxml.
However note that a JsonDataSource
will use Locale.getDefault()
format so if you have an Italian Local the Double
number es. 12.234 will be interpreted to 12234 (hence thousand).
In this case you need to set the Local to the JsonDataSource
es.
JsonDataSource ds = new JsonDataSource(new File("example.json"));
ds.setLocale(Locale.US);
To correctly parse your numbers.