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
4 Answers:
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
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 expression
if (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;
then
if (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 OK
a.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 location
in this case use:
$F{paymen}.doubleValue()!= new Double(0) .doubleValue()
that is equal to:
$F{paymen}.doubleValue()!= 0
the 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