views:

224

answers:

8

Hi

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

+14  A: 

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.

Steven Xu
+1 for the Wolfram Alpha link
Chad
+1 for link and generalizing the solution
Mandelbrot
+1  A: 

Hi,

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

tovare
This doesn't really answer the question
Mandelbrot
The question is offtopic :-)
tovare
@Mandelbrot - tovare has a point, methinks. If a developer is having issues with basic algebra, its going to be difficult to write programs on a professional level.
sheepsimulator
@sheepsimulator -- im glad someone else said it first, but thats what i was thinking
hvgotcodes
+1 because the answer doesn't deserve negative status
belisarius
Just another note - my goal here isn't to make the OP feel bad - maybe he/she just needs a refresher on algebraic equation manipulation techniques. This answer does a good job at providing a link to some rather exceptional (at least in volume) videos on solving problems of this nature.
sheepsimulator
+2  A: 

x - 0.0245x = 101.1

(1 - 0.0245)x = 101.1

x = 101.1 / (1 - 0.0245)

x = 103.639

Mandelbrot
just to clarify: 101.1 = 100 + 1.1
Tobias Langner
Thanks @Tobias. As Stephen pointed out Wolfram Alpha is your friend is you are confused by the algebra.
Mandelbrot
+4  A: 

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.

Kyra
+1  A: 
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
Will A
+1  A: 

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!

ran2
A: 

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?

Jeff M
A: 

This is not algebra, it is a basic math equation with 2 operators and 3 numbers.

The equation is:

Price * 1.0245 + 1.10 = Total

If the item costs 100€ the equation would be:

100.00 * 1.0245 + 1.10 = 103.55€

Just writing the equation this way is good enough because the proper execution of math formulas is Multiplication before addition.

NSArray
You're using variables - I was taught in school that any mathematics involving variables is algebra. Cf. wikipedia's definition of elementary algebra http://en.wikipedia.org/wiki/Algebra
sheepsimulator
So it is algebra it's not nearly as close to what they do in grade 5.
NSArray