|
-
Apr 14th, 2014, 08:51 AM
#1
Thread Starter
PowerPoster
RESOLVED - Math Question (Discounts and such)
Hello all,
This pertains to processing sales orders for a retailer.
A dollar or percentage discount can be given to an individual item in an order.
On top of that, a percentage discount can be given to the order as a whole (in which case, this percentage off is applied to each individual item in the order).
Let's say an item costing $100 is discounted $20. So the price of the item at this point is now $80.
At the end of the sale, a 30% overall discount is applied to the order. So now 30% off of the $80 (not $100) is taken for the item described above, thus discounting the item $24 more.
So the total amount off of the item is $44, and the customer pays $56 for that item.
Now - if at some later time, we wanted to look at data to reconstruct what happened on that sale, would it be possible to do so given only these three pieces of information:
Regular Price of Item = $100
Total Amount Off = $44
Order Level Discount = 30%
In other words, is there an equation that can be used to determine what portion of the $44 was a result of the 30% discount, and portion was the dollar discount?
Last edited by BruceG; Apr 14th, 2014 at 10:19 AM.
Reason: resolved
"It's cold gin time again ..."
Check out my website here.
-
Apr 14th, 2014, 08:57 AM
#2
Re: Math Question (Discounts and such)
Would it not make more sense and be easier to not store the $44 but store the amount of the discount or discounted price instead. i.e. $20 or $80
-
Apr 14th, 2014, 09:02 AM
#3
Member
Re: Math Question (Discounts and such)
not something like x + (100 - x)*0.3 = 44 ? -
-
Apr 14th, 2014, 09:13 AM
#4
Re: Math Question (Discounts and such)
-
Apr 14th, 2014, 09:21 AM
#5
Thread Starter
PowerPoster
Re: Math Question (Discounts and such)
I-and-I and dbasnett: thanks very much, I thought it might be something along those lines, but couldn't quite formulate it (what can I tell ya, it's been more years than I care to mention since I had algebra class). Now all I have to do is come up with some VB code to handle this ...
"It's cold gin time again ..."
Check out my website here.
-
Apr 14th, 2014, 09:43 AM
#6
Thread Starter
PowerPoster
Re: Math Question (Discounts and such)
Well, I'm not too proud to ask - what would the VB code look like to solve that equation?
"It's cold gin time again ..."
Check out my website here.
-
Apr 14th, 2014, 09:57 AM
#7
Member
Re: Math Question (Discounts and such)
 Originally Posted by BruceG
Well, I'm not too proud to ask - what would the VB code look like to solve that equation?
If you want to work with sales stuff you will probable work with decimals, so declare 4 doubles (give them the values you want) and just translate the formula to an x = ... ?
-
Apr 14th, 2014, 10:02 AM
#8
Thread Starter
PowerPoster
Re: Math Question (Discounts and such)
Basically, I need a function that solves for "x" (x being the DollarAmountOff), where
x + ((RegularItemPrice - x) * OrderLevelDiscount) = TotalAmountOff
"It's cold gin time again ..."
Check out my website here.
-
Apr 14th, 2014, 10:04 AM
#9
Re: Math Question (Discounts and such)
quick and dirty (my data types aren't exactly right):
Code:
Private Sub btnCalc_Click(sender As System.Object, e As System.EventArgs) Handles btnCalc.Click
Dim regPrice As Integer
Dim totalOff As Single
Dim olDiscount As Single
Dim itemDiscoutAmt As Single
Dim orderDiscountAmt As Single
regPrice = 100
totalOff = 44
olDiscount = 0.3
itemDiscoutAmt = regPrice - (regPrice - totalOff) / (1 - olDiscount)
orderDiscountAmt = totalOff - itemDiscoutAmt
End Sub
-
Apr 14th, 2014, 10:16 AM
#10
Thread Starter
PowerPoster
Re: Math Question (Discounts and such)
vbfbryce - thanks very much, that helps me out.
Thanks again to all for your help.
"It's cold gin time again ..."
Check out my website here.
-
Apr 14th, 2014, 10:26 AM
#11
Re: Math Question (Discounts and such)
 Originally Posted by BruceG
Well, I'm not too proud to ask - what would the VB code look like to solve that equation?
Code:
'based on the example
'cash discount - x
Dim cashDisc As Decimal
'item price
Dim itemPrice As Decimal = 100D
'total off
Dim totOff As Decimal = 44D
'order discount
Dim ordDisc As Decimal = 0.3D
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'x + (itemPrice - x) * ordDisc = totOff
'distribute
'x + (itemPrice * ordDisc) - (x * ordDisc) = totOff
'x - (x * ordDisc) + (itemPrice * ordDisc) = totOff
'combine like terms
'x - (x * ordDisc) in our exaqmple is .7x
Dim tempCD As Decimal = 1 - ordDisc
Dim tempIO As Decimal = itemPrice * ordDisc 'itemPrice * ordDisc
'isoalte variable
'tempCD*x + tempIO = totOff
'tempCD*x = totOff - tempIO
'(tempCD*x)/tempCD = (totOff - tempIO)/tempCD
Dim tempTO As Decimal = totOff - tempIO
'x = (tempTO)/tempCD
Dim x As Decimal = tempTO / tempCD
Debug.WriteLine(x)
End Sub
Use the debugger to step through this. One piece of advice, use Decimal for money.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|