[rules-users] Re-sending : Unexpected MVEL plus operator behavior(string-to-double), in consequence block

Kinshuk Adhikary kinshuk_in at yahoo.com
Mon Dec 21 05:11:34 EST 2009


Hi,

It does work if cast, but the logic of the + operator is what I am trying to get at.

1. Having converted them (as you said, multiplication will try to convert and it does), they ought to be now numbers. So the + operator should not concatenate, should just add the numbers.

Actually leaving messy casts all around is what is "not nice" about it.

Regards and thanks

Kinshuk

--- On Mon, 12/21/09, Swindells, Thomas <TSwindells at nds.com> wrote:

From: Swindells, Thomas <TSwindells at nds.com>
Subject: Re: [rules-users] Re-sending : Unexpected MVEL plus operator behavior(string-to-double), in consequence block
To: "Rules Users List" <rules-users at lists.jboss.org>
Date: Monday, December 21, 2009, 2:54 PM



 
 




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: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org]
On Behalf Of Kinshuk Adhikary

Sent: 21 December 2009 02:48

To: rules-users at lists.jboss.org

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 postmaster at nds.com 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 postmaster at nds.com 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


 

-----Inline Attachment Follows-----

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091221/e9c58e50/attachment.html 


More information about the rules-users mailing list