Jump to content
Changes to the Jaspersoft community edition download ×

sum of strings


Recommended Posts

Hey there

I`m new with this reporting tool

So i have database fields with values of strings

(c13,c14,c15,c16)but these string values are numbers.


And i need to sum all these fields values.In report i need to see c13+c14+c15=3+2+1=6


i created variables with expressions:

$F{C21}==null ? "0" : $F{C21}

and then used the Integer.valueOf($V{c16}) but it doesn`t worked.String and integers conflict

Post edited by: megotronx, at: 2007/06/11 13:05

Link to comment
Share on other sites

  • 5 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

you cannot test the condition $F{C21}== null. Even though it will work outside of iReport,(for reasons I do not know) this test will fail when used in a variable/group/textfield/printwhen expression.


You should just convert your strings into ints first, then do the addition...


c13.intValue() + c14.intValue() + c15...etc


Make sure that the textfield you are using has the correct class defined as well. (Don't define a String textfield and feed it int's)


Hope this helps...

Link to comment
Share on other sites

We also faced the same problem here i wanted to show data in specific pattern and if data is not there then it has to print NO_DATA the problem was if i use text field class double then i can't print NO_DATA and if i make it string then i can't achive result in desire pattern format.


We created java class for this it will take value and always return string data type if its null then it returns NO_DATA else formated value in string formate.


Hope it will be helpfull for others



Ritesh Kumar

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...