affan.shemle Posted January 12, 2014 Share Posted January 12, 2014 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 Wish10 % 10 %.98 % 0.98 %15.32 % 15.32 %100 % 100 %11.9 % 11.90 % How can I do this? Link to comment Share on other sites More sharing options...
hozawa Posted January 13, 2014 Share Posted January 13, 2014 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? Link to comment Share on other sites More sharing options...
affan.shemle Posted January 13, 2014 Author Share Posted January 13, 2014 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% Link to comment Share on other sites More sharing options...
Solution Ankur Gupta Posted January 13, 2014 Solution Share Posted January 13, 2014 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 helpsThanksAnkur Gupta http://ankurthetechie.blogspot.in/ Link to comment Share on other sites More sharing options...
affan.shemle Posted January 13, 2014 Author Share Posted January 13, 2014 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? Link to comment Share on other sites More sharing options...
Ankur Gupta Posted January 13, 2014 Share Posted January 13, 2014 Yes it is Textfield expression found in the properties of the Textfield Cheers!! ThanksAnkur Gupta http://ankurthetechie.blogspot.in/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now