Jump to content
We've recently updated our Privacy Statement, available here ×

casting to an integer


joannem

Recommended Posts

Hello,

 

I am using an xml file as my datasource. One of my fields is a comma delimited list which I split and put into an array.... I have a variable assigned for each array element... so, $V{hr1} = $V{vends}[0]... $V{hr2} = $V{vends}[1]....

 

I want to take some of my variables and add them together.

 

$V{hr1} + $V{hr2} + $V{hr3}

 

My array is defined as a string. I've tried a couple of different options of defining my variables hr1, hr2, hr3.... as integers..... as well as I've tried them as string but nothing works to be able to add them together. I can get it to concatenate the values of hr1, hr2 and hr3 but I cannot get them to add.

 

I have a variable $V(hr_int4) where the expression is

 

Integer.valueOf($V{hr1} + $V{hr2} + $V{hr3})

 

when I view this I see the concatenated values of the fields as if they were strings.

 

I've tried

 

Integer.parseInt($V[hr1} + $V{hr2} + $V{hr3})

 

it didn't work..... I get an error "Incompatible conditional types int + Integer".

 

I've also gotten the error "The operator + is undefined for the argument type(s) java.lang.Integer, java.lang.Integer.

 

If anyone can tell me what I am missing doing, it would be greatly appreciated.

 

Thanks you in advance.

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

"+" is use to concatenate string values together so you cannot do

 

Integer.parseInt($V[hr1} + $V{hr2} + $V{hr3})

 

Parse each value independently then add them up

 

Integer.parseInt($V[hr1}) + Integer.parseInt($V{hr2}) + Integer.parseInt($V{hr3}))

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...