Accepted Solution

Issue with add up numbers

Hi everybody,


I have an issue in WFA with a function used for addition.


The function is quiet simple:


def add(a,b) {a + b;}


When I use numbers, then the function is working properly, i.e. a=1 and b=1 the result is 2.

But when I use variables, constants or other functions, then the numbers will be concatenated, i.e. a=getValueAt2d(array1)=1 and b=getValueAt2d(array2)=1 the result is 11.


Will the '+' used for concatention, when variable, constants and functions will be used?

How is the correct use for it?





Re: Issue with add up numbers

[ Edited ]

I had this issue as well recently. 


The problem is MVEL is treating those numbers as strings, and that is why you are concatenating. I, for the life of me, couldn't cast the string back to an int, so I tricked MVEL.  MVEL cast the variable to an int if you multiply it.... 


def addTwo(a, b) {
(a*1) + (b*1);


Ugly, but it works.

Re: Issue with add up numbers

Hi coreywanless,


thanks for the fast reply and your suggestion.

Indeed, it's ugly, but it works. Smiley Happy