<div>While thinking this over, several things have come to my mind.</div>
<div> </div>
<div>(1) Obviously you are using double for representing monetary values. This is dangerous, as even simple calculations may result in values that are not acceptable due to accounting customs or tax laws.</div>
<div> </div>
<div>(2) The effort for checking is done for every Invoice anyway. You might consider not checking at all, but setting the correct value for all Invoice objects, disregarding the current value. (You&#39;ll have to avoid looping by settingthe rule attribute  no-loop to true.)</div>

<div> </div>
<div>(3) You could design a (Java) function that caches the calculated value based on the function arguments, but for simple formulas like the one you have shown the effort for maintaining the cache is much higher that simply calculating twice.</div>

<div> </div>
<div>(4) According to (3), just don&#39;t worry about the duplication of the effort for calculating twice, especially if you expect that the original value is correct most of the time.</div>
<div> </div>
<div>(5) Worrying about the duplication of the computational effort is fine, but I&#39;d worry even more about the duplication of the formula, which is a drag for maintenance. Tax calculations and rebate strategies are subject to change, and it would be advisable to have these formulas as static methods in your application, just once.  </div>

<div><br>-W<br> </div>
<div><span class="gmail_quote">On 7/3/09, <b class="gmail_sendername">Shabbir Dhari</b> &lt;<a href="mailto:sdhari@hotmail.com">sdhari@hotmail.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>Dear all<br><br>We are developing a financial business application that contains hundreds of business rules for validations and calculations. In the calculation rules we change the value of attribute if values past in the request is incorrect e.g.  <br>
<br>rule &quot;TaxCalc&quot;<br>    when<br>         $i : Invoice()<br>         Invoice (totalTax != (round(salesTax + (gstRate * salesAmount / 100) + importDuty – govtRebate, 2)))<br>    then<br>         i.setTotalTax(round(salesTax + (gstRate * salesAmount / 100) + importDuty – govtRebate, 2));<br>
end<br><br>The above code works perfectly fine. Only problem is the perform calculation twice. What I was looking if possible I can store calculated tax in a variable and simply assign variable to attribute if rule condiation fails. Some thing like:<br>
<br>rule &quot;TaxCalc&quot;<br>    when<br>        $i : Invoice() <br>        Invoice (totalTax != calTax : (round(salesTax + (gstRate * salesAmount / 100)+ importDuty – govtRebate, 2)))<br>    then<br>        i.setTotalTax(calTax);<br>
    end<br><br>But this does not work - shows system error at calculated value assignment. Is there any work around?<br><span class="ad"><br><br>
<hr>
Click here to find out more <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://windowslive.ninemsn.com.au/article.aspx?id=802246" target="_blank">POP access for Hotmail is here!</a></span></div><br>_______________________________________________<br>
rules-users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>