Reputation: 17
I have the original price of a commodity and its discounted price. I currently have some code but it is not working properly.
For example: The price of a pre-discounted commodity is 853.2 $. The discounted price is 349 $. That is a 59% discount, but my code shows the wrong numbers.
Dim a1 As String = (Val(pre-discounted_price) - Val(discount_price) * 100 / Val(discount_price)).ToString
Dim a2 As Integer = (853.2 - 349) * 100 / 349
Upvotes: 0
Views: 211
Reputation: 74605
The formula for calculating how much you need to discount something by, to reach a new price is:
100 * (originalprice - newprice) / originalprice
100 * (852.3 - 349) / 852.3 = 59 (0 decimal places)
Checking:
852.3 - (852.3 * 0.59) = 349 (approx)
Your code went wrong because you divided by the newprice
Upvotes: 1