开发者

How to solve this equation?

I am creating a web shop and have to calculate how much to charge the customer to make sure that the fees are cancelled. The payment system adds the fees and I want the customer to pay them.

The fees are 2.45% and € 1.10.

This means that if the customer shops for € 100, and I report that value to the payment system, we will only get € 96.45. (100 - (2.45 + 1.1)).

That is not good.

How do I calculate the right value to send to the payment system, so that we get € 100? It is not just to say € 100 + 2.45% + € 1.1 = € 103.55 and report this to the payment system. Because then the payment system will say

€ 103.55 - ((2.45% of 103.55) + 1.1)

€ 103.55 - (2,536975 + 1.1)

€ 103.55 - 3,636975

€ 99,913025

and that is, obviously, not correct.

So how do I calculat开发者_StackOverflow社区e what to send to the payment system to get the desired value?

I have come so far, that it is the following equation:

X - (X * 0.0245) - 1.10 = Y

Here, X is the desired amount to send to the payment system and Y is the amount the customer has shopped for (100), therefore:

X - (X * 0.0245) - 1.10 = 100

But how do I solve that to find out what X is?

Thanks in advance


Wolfram Alpha will solve this for you. I'm working on a more programmatic solution now.

Your equation X - (X * 0.0245) - 1.10 = Y was accurate. Let's simplify this as follows:

X - (X * 0.0245) - 1.10 = Y
X - 0.0245 * X - 1.10 = Y
(1 - 0.0245) * X - 1.10 = Y
0.9755 * X = Y + 1.10
X = (Y + 1.10)/0.9755

Per your definition, X is the desired amount, and Y is the amount the customer pays. This equation gives you Y based on X. If one of my steps is unclear, let me know.


You just have to walk through it:

X - (X * 0.0245) - 1.10 = 100
X - (X * 0.0245) = 100 + 1.10
X (1 - 0.0245) = 101.10
101.10 / x = 1 - 0.0245
101.10 = (1 - 0.0245) * x
101.10 / (1 - 0.0245)  = x
x = 103.639159

But like Steven Xu said Wolfram Alpha is your friend when you want to solve math problems.


x - 0.0245x = 101.1

(1 - 0.0245)x = 101.1

x = 101.1 / (1 - 0.0245)

x = 103.639


X - (X * 0.0245) - 1.10 = Y
X - (X * 0.0245) = Y + 1.10
X * (1 - 0.0245) = Y + 1.10
X = (Y + 1.10) / (1 - 0.0245) = (Y + 1.10) / 0.9755


I am not sure if you are serious, but if you are:

X - (X * 0.0245) - 1.10 = 100

-> 101.10 - 0.9755*x = 0 -> 101.1/0.9755 = x -> x = 103,5366

Is there any particular programming language that you want to use ? (not that this makes to much of a difference)

btw: Great answer Steven Xu!


Here's some Math videos:

http://www.khanacademy.org

Updated note: The K12-level Math question seems slightly offtopic on stackoverflow, it's not related to the programming profession. The videos are high-quality training in really basic math problems such as this one ... including percentages and basic algebra


Perhaps I've missed something throughout the discussion but are we really evaluating the correct equation in the first place?

The fees are 2.45% and €1.10. Adding those fees to a €100 order would be.

subtotal = €100
grandtotal = subtotal*(1 + 0.0245) + €1.1 = €103.55
           = subtotal + subtotal*0.0245 + €1.1 = €103.55

This yields an equation of sub*(1 + pct) + flat = tot. Solving for sub:

sub*(1 + pct) + flat = tot
sub*(1 + pct) = tot - flat
sub = (tot - flat) / (1 + pct)

or distributing sub first

sub + sub*pct + flat = tot
sub + sub*pct = tot - flat
sub*(1 + pct) = tot - flat
sub = (tot - flat) / (1 + pct)

In the end it yields the same equation sub = (tot - flat) / (1 + pct). Therefore solving for the subtotal given a grand total:

grandtotal = €103.55
subtotal = (grandtotal - €1.1) / (1 + 0.0245) = €100

Did I miss something?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜