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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

giving inaccurate percentages

Status
Not open for further replies.

ladybugz46

Technical User
Sep 26, 2002
7
0
0
US
Hi, I am admittedly new to vbscript. When posted to our site the following script appears to be reading the variables correctly but is calculating the percentages wrong. I am really hoping someone can help me with what is wrong. Thanks!!! suez

Note that this is only a sample of the array used and there is actually 260 items in the array.

Note that itempri and sku are available in the base page and the array and this code are written into that page as a file include.

Thanks!!! I sincerely appreciate all help. SueZ


Dim outletPrice(259,2)
outletPrice(0,0) = "515304GS"
outletPrice(0,1) = "45"
outletPrice(1,0) = "513864JW"
outletPrice(1,1) = "8.96"
outletPrice(2,0) = "514471JW"
outletPrice(2,1) = "13.1"
outletPrice(3,0) = "51FJ1483"
outletPrice(3,1) = "24.86"
outletPrice(4,0) = "51FJ1486"
outletPrice(4,1) = "25.79"
outletPrice(5,0) = "51FJ1484"
outletPrice(5,1) = "35.14"
outletPrice(6,0) = "513855JW"
outletPrice(6,1) = "2.88"
outletPrice(7,0) = "513713JW"
outletPrice(7,1) = "5.06"
outletPrice(8,0) = "512225JW"
outletPrice(8,1) = "3.63"
outletPrice(9,0) = "512226JW"
outletPrice(9,1) = "3.63"

'origPrice is what is uploaded to macs
'outletPrice is what is in the array (given to us by merchandising)
'savings is highest price minus what is uploaded to Macs

Dim sku
sku = Cstr(itno)
Dim origPrice
origPrice = itmpri
Dim savings
savings = outletPrice(i,1) - origPrice

For i = LBound(outletPrice) to UBound(outletPrice)
if outletPrice(i,0) = sku Then
response.write(&quot;<b>Save Over</b>    &quot; & FormatPercent((savings / outletPrice(i,1)), 0) & &quot;<br>&quot;)
response.write(&quot;Retail Price:   &quot; & FormatCurrency(outletPrice(i,1)) & &quot;<BR><br>&quot;)
response.write(&quot;Now Only:       &quot; & FormatCurrency(origPrice) & &quot;<BR>&quot;)

Else
end if
next
 
how is it not calculating correctly. as long as savings is a smaller number then outletPrice then the function will work correctly, however if you run into the oposite of that it will not.
for instance this
savings = &quot;12.32&quot;
outletPrice = &quot;1.11&quot;
alert FormatPercent((savings / outletPrice), 0)
outputs like 1100%
but this
savings = &quot;12.32&quot;
outletPrice = &quot;211.11&quot;
alert FormatPercent((savings / outletPrice), 0)
outputs 6% which is the correct syntax for the function. A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
onpnt...

What you are describing is similar to what is happening. The origPrice on the entire sale was set up to be all 50% off initially.

For example:

outletPrice : $8.96
origPrice : $4.48
outputs: (savings: $4.48) 452%

However: the following numbers work:
outletPrice : $45.00
origPrice : $22.50
outputs: (savings: $22.50) 50%

Any ideas why one number would work and the other one not?
Any help would be appreciated.

Many many thanks for stepping in to help!! Suez
 
I'm getting a little confused because the first example outputs 50% also with the second, and if you do a backwards devision then it outputs 200% not 452%

I tested the array against it as well and it outputs 50% when I did this
Dim outletPrice2(1,1)
outletPrice2(0,0) = &quot;515304GS&quot;
outletPrice2(0,1) = &quot;45&quot;
savings = &quot;22.50&quot;
alert FormatPercent((savings / outletPrice2(0,1)), 0)

am I missing something

A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
onpnt...

Dim outletPrice2(1,1)
outletPrice2(0,0) = &quot;515304GS&quot;
outletPrice2(0,1) = &quot;45&quot;
savings = &quot;22.50&quot;
alert FormatPercent((savings / outletPrice2(0,1)), 0)

this example above is the 0 entry in the array and it is the one that will come out right, that is, 50%.

I know this is probably something simple I am missing...also I am not sure what you mean by backwards division.....

Could this have absolutely anything to do with either the looping through the array or the face that the array and its code is in an include file? Thanks.


?? I sincerely appreciate your help on this. I am very confused also and need it to work. Feel free to contact me directly at sue@firemtn.com or aol buggz46

sue
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top