EmKay
EmKay

Reputation: 1089

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 calculate 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

Upvotes: 0

Views: 514

Answers (7)

Jeff Mercado
Jeff Mercado

Reputation: 134521

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?

Upvotes: 0

tovare
tovare

Reputation: 4087

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

Upvotes: 1

Matt Bannert
Matt Bannert

Reputation: 28274

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!

Upvotes: 1

Will A
Will A

Reputation: 25008

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

Upvotes: 1

Kyra
Kyra

Reputation: 5407

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.

Upvotes: 4

Mandelbrot
Mandelbrot

Reputation: 512

x - 0.0245x = 101.1

(1 - 0.0245)x = 101.1

x = 101.1 / (1 - 0.0245)

x = 103.639

Upvotes: 2

Steven
Steven

Reputation: 18014

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.

Upvotes: 14

Related Questions