This may be a simple problem but I can seem to figure it out...
I'm writing a piece of software that sends payments though Paypal. PayPal charges a 2% fee per transaction that we in turn want to take out of the users payment.
For smaller transactions I can use the simple math of taking the transaction fee amount out before we send the payment and because of rounding the math will work out.
However, with larger transactions, because I am taking the fee out before sending it to Paypal, the actual fee applied to the transaction becomes less than what I took out.
For example:
If I need to send 100, we first take the 2% out and send 98. Then Paypal applies a fee 1.96. Thus we have ended up with .04 overbalance.
Is there an equation I can use to correct this balance?