Help Please!!! Adding two Double values....
Posted on July 20, 2009 at 11:04am
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...
Joined: Jul 20 2009 - 10:27am
Last seen: 14 years 2 months ago
Posted on July 21, 2009 at 8:09am
you can solve this by using an expression like this "variable1.doubleValue()+variable2.doubleValue()"
Joined: Jul 21 2009 - 7:46am
Last seen: 14 years 2 months ago
Posted on July 21, 2009 at 10:08pm
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...
Joined: Jul 20 2009 - 10:27am
Last seen: 14 years 2 months ago
Posted on July 22, 2009 at 2:28am
It is a Java. Ok. The correct code should be like this one:
Double.valueOf($f{variable1}.doubleValue()+$f{variable2}.doubleValue())
Joined: Jul 21 2009 - 7:46am
Last seen: 14 years 2 months ago
Posted on July 22, 2009 at 5:45am
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 :)
Joined: Jul 20 2009 - 10:27am
Last seen: 14 years 2 months ago
Posted on March 28, 2012 at 8:39am
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.
Joined: Sep 21 2011 - 10:35am
Last seen: 4 years 10 months ago
new Double( $f{variable1}.doubleValue()+$f{variable2}.doubleValue()) would work too