I am using iReport to create a report that is based on Oracle SQL query. There is a % column in my report values of which are in percent like 10 %, .98 %, etc. I want the column to look like "Wish" as shown below:
Existing Wish
10 % 10 %
.98 % 0.98 %
15.32 % 15.32 %
100 % 100 %
11.9 % 11.90 %
How can I do this?
3 Answers:
Hi ,
This could be done by including the expression like for the text field which contains the percentage :
I have assumed that the percentage coming from the datasource is of double type.
For the case When the Percentage coming from the Data source is already calculated percentages.
($F{percentage} - $F{percentage}.intValue() !=0 )
? new java.text.DecimalFormat("###.00 ").format($F{percentage}) + " %"
: new java.text.DecimalFormat("###0 ").format($F{percentage}) + " %"
For the case When the Percentage coming from the Data source is not calculated percentages and needs to be multiplied with 100 or calculated.
($F{percentage} - $F{percentage}.intValue() !=0 )
? new java.text.DecimalFormat("###.00 %").format($F{percentage})
: new java.text.DecimalFormat("###0 %").format($F{percentage})
Hope that this helps
Thanks
Ankur Gupta
http://ankurthetechie.blogspot.in/
I'm not sure about your question. Is your question that if you use format "0.00", 10% and 100% will appear as 10.00% and 100.00%?
You want to know how to use a "if" condition to select format?
Yes it is Textfield expression found in the properties of the Textfield
Cheers!!
Thanks
Ankur Gupta
http://ankurthetechie.blogspot.in/
Thanks Ankur. Right now I have modified my Oracle SQL query to convert the numbers in specific format model using to_char(n, '990.99') and it is giving me desired result. Can you tell me if I have to format the numbers in iReport instead of query in future where I am suppose to put the code given by you? Is it in the text field expression properties in the properties window?