• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Math Evaluate

LEGEND ,
Dec 07, 2006 Dec 07, 2006

Copy link to clipboard

Copied

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


TOPICS
Advanced techniques

Views

393

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 07, 2006 Dec 07, 2006

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 07, 2006 Dec 07, 2006

Copy link to clipboard

Copied

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>
>
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 07, 2006 Dec 07, 2006

Copy link to clipboard

Copied

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>
>
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 08, 2006 Dec 08, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 08, 2006 Dec 08, 2006

Copy link to clipboard

Copied

LATEST
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.
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation