Help Please!!! Adding two Double values....

Hi Guys!

I am new to Jaspers IReport . I use this in netbeans 6.5 for reporting but I am facing one problem------>>>

I have two fields whose Expression class java.lang.Double, whose values are taken from database.

Now I want to add those two fields and display in Third Field, But whenever I use + operator to add those two fields in third field expression it gives me error " The operator +  is undefined for the argument type(s) java.lang.Double,  java.lang.Double"

I dont know why its not allowing to add two Double fields.. 

So please guys help me out with this problem....

Thanks in Advance...

chiragkini's picture
Joined: Jul 20 2009 - 10:27am
Last seen: 14 years 2 months ago

6 Answers:

you can solve this by using an expression like this "variable1.doubleValue()+variable2.doubleValue()"
oxelad's picture
255
Joined: Jul 21 2009 - 7:46am
Last seen: 14 years 2 months ago
Thanks Oxelad, But when I tried to do this it gives me error saying "Cannot cast from double to Double" so even if when i tried to convert values first into string the convert into double it fails. For eg. when i do ($f{variable1}.toString()).doubleValue() +($f{variable2}.toString()).doubleValue() , it gives me error: "The method doubleValue() is undefined for type String.... Note: my variable values comes from database tables of type DOUBLE. Hope u got it what is scenario...
chiragkini's picture
Joined: Jul 20 2009 - 10:27am
Last seen: 14 years 2 months ago
It is a Java. Ok. The correct code should be like this one: Double.valueOf($f{variable1}.doubleValue()+$f{variable2}.doubleValue())
oxelad's picture
255
Joined: Jul 21 2009 - 7:46am
Last seen: 14 years 2 months ago

new Double( $f{variable1}.doubleValue()+$f{variable2}.doubleValue()) would work too

shareef.hiasat - 9 years 3 months ago
Hey Thanks Oxelad, thanks a ton. Its working now, actually I was doing stupiity by using Double.valueOf($f{variable1}.doubleValue()) + Double.valueOf($f{variable2}.doubleValue()). I got my mistake ... Thanks once again :)
chiragkini's picture
Joined: Jul 20 2009 - 10:27am
Last seen: 14 years 2 months ago

Oxelad.  Thanks a lot.  I am constantly struggling with Java in Jasper.  This helped me a lot.  I think this will save me lots of time in the future.

tomcushing70's picture
Joined: Sep 21 2011 - 10:35am
Last seen: 4 years 10 months ago
Feedback