atmaling Posted June 21, 2008 Share Posted June 21, 2008 HI All,While using iReport i got one problem.I am displaying values from a table. column fields are "name","roll","marks".I want to display dash i.e. "--" when the value of "marks" field is ZERO.As now I am getting following output.Name Roll MarksJohn 51 66Tom 21 0Harry 12 0 Expected Output I want following OUTPUTName Roll MarksJohn 51 66Tom 21 --Harry 12 -- Please help me Thanks in AdvanceCode:Code:[code]Code:[code]Code:[code] Link to comment Share on other sites More sharing options...
C-Box Posted June 23, 2008 Share Posted June 23, 2008 Use this for the TextExpression: Code:(BigDecimal.ZERO)equals($F{marks})?"--":$F{marks}.toString() (assume, that your field "marks" is BigDecimal!?!?Should work. hthC-Box Link to comment Share on other sites More sharing options...
atmaling Posted June 23, 2008 Author Share Posted June 23, 2008 Thanks friend, CBox.... I tried ur method but its giving error as "BigDecimal.ZEROÂcannotÂbeÂresolvedÂtoÂaÂtype".I dont know too much about iReport. PLzz help me. Thanks in advance. Link to comment Share on other sites More sharing options...
C-Box Posted June 23, 2008 Share Posted June 23, 2008 Hmmm perhaps I forgot just a point before equals (answered just from mind, without any iReport/IDE open) try this one: Code:(BigDecimal.ZERO).equals($F{marks})?"--":$F{marks}.toString() This is just a simple Java comparison. Means: If your field "marks" is BigDecimal Zero than print "--" otherwise print the content of your field "marks" hth nowC-Box Link to comment Share on other sites More sharing options...
C-Box Posted June 23, 2008 Share Posted June 23, 2008 otherwise try this: Code:(BigDecimal.ZERO.compareTo($F{marks}) == 0)?"--":$F{marks} this should also work.C-Box (Still assume, that your field is of type "BigDecimal") Link to comment Share on other sites More sharing options...
Solution atmaling Posted June 24, 2008 Author Solution Share Posted June 24, 2008 Thanks very much friend.BUt this is not working. Its giving error message as "IncompatibleÂconditionalÂoperandÂtypesÂStringÂandÂBigDecimal" But I did by other method and its working fine.I changed the field type "marks" to String and then I wrote following expression in Text field expression "$F{marks}.equals("0") ? "--" : $F{marks}" make sure that "marks" field should be String Link to comment Share on other sites More sharing options...
C-Box Posted June 25, 2008 Share Posted June 25, 2008 That's why I wrote: (Still assume, that your field is of type "BigDecimal") But anyway, fine if it's working now! :-) regardsC-Box Link to comment Share on other sites More sharing options...
ramy Posted August 20, 2008 Share Posted August 20, 2008 I have a similar question to the one above except that I'd like to keep my output as a double. So, my code looks like this: ($F{WinnersReturn} == null) ? "N/A" : $F{WinnersReturn} The reason I don't want to use the "toString()" function at the end of $F{WinnersReturn} is because I want to format the output to a percentage if the field is NOT NULL.I tried tricking it into thinking "N/A" was a double by doing: new Double("N/A") but, obviously, that gave me an error while filling.Thanks in advance,_ramy 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