0

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

4
  • 2
    Sounds like you've misstated the formula. There's a difference between "between 2.45% and 1.10" (ie: the min or max of the two), or "2.45% + 1.10". Make sure the formula you're using matches what the payment processor will use.
    – cHao
    Jul 15, 2010 at 21:26
  • Just make sure you don't do this in binary floating point math.
    – Joren
    Jul 15, 2010 at 21:36
  • @Joren doing this in binary is less serious than many think because operations this simple will not introduce enough errors when rounded according to accounting practices. The poster would be wise to have accounting advice on the solution and also check the legal matters of adding forwarding transaction fees to the customer (many credit cards don't allow it).
    – tovare
    Jul 15, 2010 at 21:49
  • Just wait for the infinities and NaNs ... also stackoverflow will yell at you ;-)
    – Joren
    Jul 15, 2010 at 23:46

7 Answers 7

14

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.

0
4

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.

2

x - 0.0245x = 101.1

(1 - 0.0245)x = 101.1

x = 101.1 / (1 - 0.0245)

x = 103.639

2
  • just to clarify: 101.1 = 100 + 1.1 Jul 15, 2010 at 21:27
  • Thanks @Tobias. As Stephen pointed out Wolfram Alpha is your friend is you are confused by the algebra.
    – Mandelbrot
    Jul 15, 2010 at 21:31
1
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
1

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!

1

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

4
  • 1
    This doesn't really answer the question
    – Mandelbrot
    Jul 15, 2010 at 21:29
  • 2
    @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.
    – J. Polfer
    Jul 15, 2010 at 21:52
  • 1
    @sheepsimulator -- im glad someone else said it first, but thats what i was thinking
    – hvgotcodes
    Jul 15, 2010 at 22:19
  • 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.
    – J. Polfer
    Jul 16, 2010 at 17:39
0

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.