• Toll-free  888-665-8637
  • International  +1 717-220-0012
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

avmwebguy
#1 Posted : Thursday, April 10, 2008 1:45:44 PM(UTC)
avmwebguy

Rank: Member

Joined: 1/24/2008(UTC)
Posts: 60

The Percentage Increase/Decrease calculation formula is strange. . .


Scenario:

Say you want to raise all of your product prices by 10%. You go into the batch product editor and raise site price 10%.

Then you want to off 10% off to certain customers via a price group.


The prices do Not match the original prices.

Example:

Product A Price: $100

You raise price by 10%.

Product A Price: $110

Customer 1 is in Price group that gives 10% off.

Product A Price for Customer 1: $99

It *should* be $100, but its $99 instead. This becomes a problem when you are dealing with large prices like $2000.



This code is located in BVSoftware.BVC5.Core > Utilities > Utilities.vb

BV Commerce Formula:



Code:

Public Shared Function ApplyDiscountPercent(ByVal monetaryAmount As Decimal, ByVal percentage As Decimal) As Decimal
Return Math.Round((monetaryAmount * ((100 - percentage) / 100)), 2)
End Function

Public Shared Function ApplyIncreasedPercent(ByVal monetaryAmount As Decimal, ByVal percentage As Decimal) As Decimal
Return Math.Round((monetaryAmount * ((100 + percentage) / 100)), 2)
End Function



Solution:



Correct Forumla:

Code:

Public Shared Function ApplyDiscountPercent(ByVal monetaryAmount As Decimal, ByVal percentage As Decimal) As Decimal
'Return Math.Round((monetaryAmount * ((100 - percentage) / 100)), 2)
percentage = percentage / 100 + 1
Return Math.Round((monetaryAmount / percentage), 2)
End Function

Public Shared Function ApplyIncreasedPercent(ByVal monetaryAmount As Decimal, ByVal percentage As Decimal) As Decimal
'Return Math.Round((monetaryAmount * ((100 + percentage) / 100)), 2)
percentage = percentage / 100 + 1
Return Math.Round((monetaryAmount * percentage), 2)
End Function



Effectively this changes the formula to:

Amount * 1.x

Where x = Percent to add.


Or

Amount / 1.x

Where x = Percent to subtract.


Using this formula you can add 10% and then subtract 10% and end up with the original number.

Please make this modification to your code for future releases.
- Brian

Web Developer/IT Manager
Marcus
#2 Posted : Thursday, April 10, 2008 2:02:16 PM(UTC)
Marcus

Rank: Member

Joined: 11/5/2003(UTC)
Posts: 1,786

Brian,

10% of 110 is $11.

When you batch edit prices up you are reseting the price of the product to $110. Then you are taking 10% off.

It's like when you buy a stock for $100 and it goes up 10% to $110. next week it drop back to $100. The percentage drop is actually 9.09% and CNBC would say that the stock is "down 9% today in trading."
avmwebguy
#3 Posted : Thursday, April 10, 2008 2:55:28 PM(UTC)
avmwebguy

Rank: Member

Joined: 1/24/2008(UTC)
Posts: 60

Yeah. . . that's what I told my bosses. . . but they didn't like not being able to go back down 10% and hit the exact number that we started from. . .


So perhaps the actual calculation isn't *wrong* per say, but its not what we were expecting it to be like.




The Add Percent seems to be fine, but its the subtracting that gives the different answer. . .


I don't know exactly what to call my calculation because technically its not subtracting 10%. . . but it reverses the 10% increase of the original number.

Normal Way:
2000 + 10% = 2200
2200 - 10% = 1980

My Way:
2000 * 1.1 = 2200
2200 / 1.1 = 2000


LOL.


Here's some fun calculations:


100 - 10% = 90
90 + 10% = 99


100 / 1.1 = 90.909090909090909090909090909091
90.909090909090909090909090909091 * 1.1 = 100


. . . . I *hate* math. . .
- Brian

Web Developer/IT Manager
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

©2024 Develisys. All rights reserved.
  • Toll-free  888-665-8637
  • International  +1 717-220-0012