.98 % to 0.98 %

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?

affan.shemle's picture
Joined: Oct 9 2013 - 1:28am
Last seen: 9 years 8 months ago

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/
 

Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 1 day 4 hours ago

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?

affan.shemle - 9 years 8 months ago

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?

hozawa's picture
190873
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 years 3 months ago

Thanks Hozawa. Following is the answer to your question:
10% and 100% should appear as 10% and 100%
However, .98% and 98.1% should appear as 0.98% and 98.10%

affan.shemle - 9 years 8 months ago

Yes it is Textfield expression found in the properties of the Textfield 

Cheers!!

 

Thanks
Ankur Gupta 
http://ankurthetechie.blogspot.in/
 

 

Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 1 day 4 hours ago
Feedback