purnama Posted June 14, 2010 Share Posted June 14, 2010 how to use expression with double ?i have expression in jasper 2.0.2 like this :($F{paymen}!= new Double(0) ? $F{payStat}+":"+$F{paymen1}.intValue()+"\n" : "" )but it didn't work ? i need your help..btw, sory if my english is bad Link to comment Share on other sites More sharing options...
slow Posted June 14, 2010 Share Posted June 14, 2010 use:($F{paymen}!=null && $F{paymen}.doubleValue()!=0)?($F{payStat}+":"+$F{paymen1}.intValue()+"\n"):""i suppose:-paymen is a Double object... and -payStat is a String and -paymen1 is a Integer.if paymen1 is a Double, then use, ($F{paymen}!=null && $F{paymen}.doubleValue()!=0)?($F{payStat}+":"+$F{paymen1}.doubleValue()+"\n"):"" _________________________________________if it works... give me KARMA points please! : ) _________________________________________listening: Nine Inch Nails - Complication Link to comment Share on other sites More sharing options...
purnama Posted June 15, 2010 Author Share Posted June 15, 2010 ok thank you Mr.slow and i will give you KARMA points.but i have a question. why expression -> 1. $F{paymen}!= new Double(0) ? or 2. $F{paymen}!= 0 ?didn't work. can you explain to me Link to comment Share on other sites More sharing options...
slow Posted June 15, 2010 Share Posted June 15, 2010 the explanation will give me some extra karma points? :)when you work with java objects the the "equal" or "==" concept must be relative to them (object)...so, when you declare:Double A = new Double(0);Double B= new Double(0);the expressionif (A==B) then System.out.println("OK :) ")else System.out.println("NO :( ")will print NO :(this happen because you try to compare the value of A and B that aren't 0, but some value on memory location that contains the 0 value... so A point to a location, B point to another location... and all two location contains the 0 value... but their real values (remember A and B is a memory location!) are different.if you declare Double A = new Double(1);Double B = A;thenif (A==B) then System.out.println("OK :) ")else System.out.println("NO :( ")will print OK :) only because A and B point to the same memory location... (remember that also in this case you are comparing memory location, not double values!)SO... the best (and only) way to perform a comparison is to compare the VALUES of the two variables...if (A.doubleValue()==B.doubleValue()) then System.out.println("OK :) ")else System.out.println("NO :( ")will print OKa.doubleValue() returns a basic double value, not an object... so its value can be used in algebra, comparison etc etc.--------------------------------------------in reference to your question:$F{paymen}!= new Double(0) ? it doesn't work because $F{paymen} is a Double object... and new Double(0) is another Double object pointing to different memory locationin this case use:$F{paymen}.doubleValue()!= new Double(0) .doubleValue()that is equal to:$F{paymen}.doubleValue()!= 0the second question:$F{paymen}!= 0 ?it doesn't work because you try to compare a Double object with an int/double basic value... this mean that you try to compare a memory location value with the 0 value!the correct form is:$F{paymen}.doubleValue()!= 0 I hope what I wrote may make your ideas more clear. _________________________________________if it works... give me KARMA points please! : ) _________________________________________listening: Nine Inch Nails - The Day The World Went Away Post Edited by slow at 06/15/2010 07:35 Link to comment Share on other sites More sharing options...
purnama Posted June 15, 2010 Author Share Posted June 15, 2010 ooo.. Now i understand.thank you very much for your answer... and i will give some extra karma points.. ha ha ha 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