Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluate Functionality

Status
Not open for further replies.

fusionaire

Programmer
May 20, 2000
67
US
I have a site in which the user's input is pulled out on the final page, and then those values are either multiplied or added to, depending on the user's choice. Then at the end, all those values must be added and multiplied together. I am having trouble with CF and the multiplication after an addition action. Any suggestions would be great!<br><br>HERE IS THE CODE:<br>&lt;cfif pick.BaseRate IS &quot;Standard&quot;&gt;<br>&lt;cfoutput&gt;<br>&lt;font size=&quot;2&quot;&gt;&lt;b&gt;QUOTE TOTAL:&nbsp;&nbsp;$Evaluate#stan.bodily_injury_pd * tory.BIPD&nbsp;&nbsp;+ stan.Uninsured_motorist * tory.um + stan.underinsured_motorist * tory.uim + stan.medical * tory.meds + stan.income_loss + stan.accidental_death + stan.funeral + tory.comp * myear.comprehensive + tory.coll * myear.collision#&nbsp;&nbsp;per 6 months&lt;/b&gt;&lt;/font&gt;&lt;/cfoutput&gt;&lt;/cfif&gt;
 
CF uses standard order of operations, meaning that it will do all multiplication in a problem before it does addition.<br><br>1+3*2 equals 7.&nbsp;&nbsp;(1+3)*2=8...<br><br>Try using parentheses to force the order you want your problem to be handled in.&nbsp;&nbsp;If you want your problem to be figured out in the order you have it, it should look something like:<br><br>((((((((((stan.bodily_injury_pd * tory.BIPD&nbsp;&nbsp;+ stan.Uninsured_motorist) * tory.um) + stan.underinsured_motorist) * tory.uim + stan.medical * tory.meds) + stan.income_loss) + stan.accidental_death) + stan.funeral) + tory.comp) * myear.comprehensive) + tory.coll) * myear.collision<br><br>Or so it makes more sense visually:<br><br>&lt;cfset TOTAL=stan.bodily_injury_pd * tory.BIPD&gt;<br>&lt;cfset TOTAL=TOTAL + stan.Uninsured_motorist&gt;<br>&lt;cfset TOTAL=TOTAL * tory.um&gt;<br>&lt;cfset TOTAL=TOTAL + underinsured_motorist&gt;<br>&lt;cfset TOTAL=TOTAL * tory.uim&gt;<br>&lt;cfset TOTAL=TOTAL + stan.medical&gt;<br>&lt;cfset TOTAL=TOTAL * tory.meds&gt;<br>&lt;cfset TOTAL=TOTAL + stan.income_loss&gt;<br>&lt;cfset TOTAL=TOTAL + stan.accidental_death&gt;<br>&lt;cfset TOTAL=TOTAL + stan.funeral&gt;<br>&lt;cfset TOTAL=TOTAL + tory.comp&gt;<br>&lt;cfset TOTAL=TOTAL * myear.comprehensive&gt;<br>&lt;cfset TOTAL=TOTAL + tory.col&gt;<br>&lt;cfset TOTAL=TOTAL * myear.collision&gt;<br><br>&lt;cfoutput&gt;#TOTAL#&lt;/cfoutput&gt;
 
ColdFusion functions need to be wrapped in # symbols, therefore you are not evaluating anything, jut outputting the word evaluate, also you missed the parentheses.<br><br>#Evaluate(stan.bodily_injury_pd * tory.BIPD&nbsp;&nbsp;+ stan.Uninsured_motorist * tory.um + stan.underinsured_motorist * tory.uim + stan.medical * tory.meds + stan.income_loss + stan.accidental_death + stan.funeral + tory.comp * myear.comprehensive + tory.coll * myear.collision)#<br><br>You also may need to group the various calulations in parentheses as well to make sure they are performed in the correct order.<br><br> <p>Russ Michaels<br><a href=mailto:russ@satachi.com>russ@satachi.com</a><br><a href= Internet Development</a><br>For my personal book recommendations visit <br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top