Jasper Reports doesn't format number when running report from Java code

I've created report using iReport 4.5.1 which contains tables with fields of amount values. Value of "Pattern" property of these fields is "$ #,##0.00". When I run report from iReport I see right formatted amount, but when I run report from Java code (library version is 5.0.0), I see same amounts but without formatting. Why formatting disappears when I run report from Java code? How to fix it?

tural.muradbeyli's picture
Joined: Feb 24 2013 - 8:32am
Last seen: 8 years 2 months ago

1 Answer:

Hi tural,

The formatting done in the iReport is report specific it like extra utility , of providing the pattern provided by the iReport. When you run that in java code the formatting is removed. So what you can do for the java code is that you could use:

 new java.text.DecimalFormat("pattern").format(put the field here)


So to provide similarity in the report and in the Java code what can be done is that you could replace the expression of the text field with the same expression and the discrepancy could be easily taken care off.In that case the expression would look something like this

 new java.text.DecimalFormat("¤ #,##0").format($F{VALUE})   

Now here the in the field expression easily , any field or parameter could be put and same would work fine for java code too,


Hope that it solves your query




Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 1 month 3 weeks ago