My gut instinct would say that this is possibly correct.
I've not looked at the mvel code but if all your types are strings then it 
makes sense for it to pick the most type specific operator first. 
Multiplication only works on numbers so it attempts to convert them but the + 
operator is defined on strings and therefore is a closer match for strings as 
you are assigning the result to a string.
I haven't tried it but you could liberally sprinkling in brackets and type 
casts to get what you want, eg:
t.out = (double)(t.in2*t.in3) + (double)(t.in3*t.in4) + (double)(t.in2*t.in4);

Thomas

From: [email protected] 
[mailto:[email protected]] On Behalf Of Kinshuk Adhikary
Sent: 21 December 2009 02:48
To: [email protected]
Subject: [rules-users] Re-sending : Unexpected MVEL plus operator 
behavior(string-to-double), in consequence block

Using
drools 5.1
mvel 2-2.0.14

In consequence (then) block : (dialect strict or not does not make a difference)

Trying to sum up some numbers after a multiplication operation. For example :

t.out = t.in2*t.in3 + t.in3*t.in4 + t.in2*t.in4;

(the object t has all its attributes of the type String), all the t.in 
parameters are actually numbers-as-strings.

So the multiplication is going on fine, as expected, but the addition (+) sign, 
is concatenating instead of adding.

So the for inputs "1", "2" and "3", the result looks something like : 2.06.03.0 
 (i.e concetenated) instead of the expected 11.0.

What is going worng  How does the + operator decide to do concat instead of 
doing addition.

Any documentation on this + operator logic ?

Note : The above works fine when I use MVEL without Drools.

Thanks



________________________________

**************************************************************************************
This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
[email protected] and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes. To protect the environment please do not 
print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, 
United Kingdom. A company registered in England and Wales. Registered no. 
3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

________________________________
This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
[email protected] and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.

An NDS Group Limited company. www.nds.com
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to