Search code examples
formattingjasper-reports

iReport multiplying in percentage pattern


I'm working with iReport 2.0.5 (because I have to) and I have a little issue formatting percentages. When I use an unformatted double this is what I get:

0
22,22
5,555 (this is the average of the whole group)
100
100  (this is the average of the whole group)

The average is calculated OK

But when I set the pattern #,##0.00 % using iReport 2.0.5 this happens:

0,00 %
2.222,00 %
555,50 % (this is the average of the whole group)
10.000,00 %
10.000,00 % (this is the average of the whole group)

How do I stop the values from changing?


Solution

  • 22,22 is 2.222,00 % what you need is 0.2222 so this is a solution (just dived by 100)

    In old version expression it is achieved like this:

    new Double($F{percentageVar}.doubleValue()/100d)
    

    So your textField (hoping that $F{percentageVar} is never null) is

    <textField isStretchWithOverflow="true" pattern="#,##0.00 %" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement x="694" y="0" width="88" height="20" key="textField-8"/> <box></box> <textElement textAlignment="Right" verticalAlignment="Middle"> <font/> </textElement> <textFieldExpression class="java.lang.Double"><![CDATA[new Double($F{percentageVar}.doubleValue()/100d)]]></textFieldExpression> </textField>