Skip to main content
Inspiring
December 8, 2006
Question

Math Evaluate

  • December 8, 2006
  • 5 replies
  • 423 views
I have a shopping cart and I have the Installation of each item set up as a
price. I have the install total for each item set to the Install price times
the qty ordered. Then at the bottom of the cart I need to get the install
total for all the items. That's where I am stuck. The set up looks like
this:


Item Qty. Install
As5D 2 $280.00

75GVC 1 $69.00

Total Installation: #349.00 >>>>> this is the number I need and can't figure
out.

The Install for each item is using the following formula:
<CFSET TheInstall = Evaluate((MyCart[TheIndex][6]) * (MyCart[TheIndex][3]))>

How would I get the total installation?? I thought about using a list
function, but I don't know exactly which function to use, or how to get them
all added together at the end.

Thanks,

Kim


This topic has been closed for replies.

5 replies

Inspiring
December 8, 2006
That was my thought as well. But it didn't work and I don't know what I was
doing that was wrong so I added a <CFIF TheInstall EQ '0'>that is blank if
its equal to zero, but does the math if it's not.

Kim

"[CJ]" <webforumsuser@macromedia.com> wrote in message
news:elcdpv$f4$1@forums.macromedia.com...
> you don't need the evaluate because it's extraneous.
>
> <cfset myValue = 5 * 4 /> <-- sets myValue to 20
>
> as far as your 0 issue... unless I misunderstood how your structure is set
> up
> (my understanding is element 6 is price and element 3 is quantity), it
> shouldn't matter if price is 0 for a given item. 0 * (whatever the
> quantity)
> is 0 for price...but that gets ADDED to the grandTotal value. so if
> during a
> given loop iteration, grandTotal is 10.50 and you add 0, you still get
> 10.50.
>


December 8, 2006
you don't need the evaluate because it's extraneous.

<cfset myValue = 5 * 4 /> <-- sets myValue to 20

as far as your 0 issue... unless I misunderstood how your structure is set up (my understanding is element 6 is price and element 3 is quantity), it shouldn't matter if price is 0 for a given item. 0 * (whatever the quantity) is 0 for price...but that gets ADDED to the grandTotal value. so if during a given loop iteration, grandTotal is 10.50 and you add 0, you still get 10.50.
Inspiring
December 8, 2006
Ok, CJ, the problem I am having is that some installation prices are set to
'0' so, of course when zero is times by anything the answer is zero. Which
wipes out my install total.

Kim
"[CJ]" <webforumsuser@macromedia.com> wrote in message
news:elac13$ft7$1@forums.macromedia.com...
> you don't need evaluate() in your calculation.
> <cfset theInstall = myCart[TheIndex][6] * myCart[TheIndex][3] /> will do.
>
> to get the grand total, just loop over myCart performing the calculations.
> <cfset grandTotal = 0 />
> <cfloop from="1" to="#arrayLen(myCart)#" index="idx">
> <cfset grandTotal = grandTotal + (myCart[idx][6] * myCart[idx][3]) />
> </cfloop>
> <cfoutput>#grandTotal#</cfoutput>
>
>


Inspiring
December 8, 2006
I appreciate your response. But in my quest to learn would you mind telling
me why I don't need the evaluate?

I will give this a try.

Kim

"[CJ]" <webforumsuser@macromedia.com> wrote in message
news:elac13$ft7$1@forums.macromedia.com...
> you don't need evaluate() in your calculation.
> <cfset theInstall = myCart[TheIndex][6] * myCart[TheIndex][3] /> will do.
>
> to get the grand total, just loop over myCart performing the calculations.
> <cfset grandTotal = 0 />
> <cfloop from="1" to="#arrayLen(myCart)#" index="idx">
> <cfset grandTotal = grandTotal + (myCart[idx][6] * myCart[idx][3]) />
> </cfloop>
> <cfoutput>#grandTotal#</cfoutput>
>
>


December 8, 2006
you don't need evaluate() in your calculation.
<cfset theInstall = myCart[TheIndex][6] * myCart[TheIndex][3] /> will do.

to get the grand total, just loop over myCart performing the calculations.
<cfset grandTotal = 0 />
<cfloop from="1" to="#arrayLen(myCart)#" index="idx">
<cfset grandTotal = grandTotal + (myCart[idx][6] * myCart[idx][3]) />
</cfloop>
<cfoutput>#grandTotal#</cfoutput>