I have 1 result and which i will receive in Bank account, Based on that account i have to Put a balance to user account.
How can you find the Handling cost from total tried 491.50 / 0.95 = 517.36 which is wrong ? It should be 500.00 (to my expectation)
User balance requires 500.00
When 500.00 selected he gets 5% discount
There is a handling cost for this
ex:
1) Discount: 500.00 - 5% = 475.00
2) Handling cost: (475.00 x 0.034) + 0.35 = 16.50
3) Total: 475.00 + 16.50 = 491.50
So problem is from 491.50, i have to find atleast handling cost to get promised Balance.
Any solution ? Cant figure it out myself...
In short cut:
a) i put 491.50 -> b) my formula will suggest me apply balance 500.00 (which is the main goal)
So, your maths can be represented as:
((0.95 * initialCost * 0.034) + 0.35) + (0.95 * initialCost ) = finalCost
which reduces to
(0.9823 * initialCost) + 0.35 = finalCost
It follows that
initialCost = (finalCost - 0.35) / 0.9823
(final_price - 0.35) / 1.034 / 0.95
For 491.50, this yields 500.
You might try to combine the last 2 divisions to be divide by 1.034 * 0.95 = 0.9823, but you will have to guard against rounding errors due to using floating point arithmetic.
Related
I ran into scenario where my client wants to know the original amount after percentage deduction. They are collecting online donation where user enter its amount and then percentage values (bank charges and FED) are added in his amount to ensure that my client always get exact amount in his account after percentage deduction.
For example:
Donation amount = 32,000
Bank charges = 3%
FED charges = 13%
Calculation:
Deducting bank charges = 32000 * .03 = 960
Deducting FED on bank charges = 960 * .13 = 124.80
Total = 32000 + 960 + 124.80 = 33,084.80
I now want to reverse the amount 33,084.80 to get the exact actual amount of 32,000.
Let Bank charges = b, FED charges = f (here b=0.03, f=0.13)
Then
Donation + Donation * b + Donation * b * f = Total
Donation * (1 + b + b * f) = Total
so
Donation = Total / (1 + b + b * f)
here
Donation = 33,084.80 / (1 + 0.03 + 0.03 * 0.13) = 33,084.80 / 1.0339 = 32,000
I'm guessing this is simple but I am having a hard time working this out. The formula I have is this: (1-x) / 0.20. x equals between 0.8 and 1. Example:
(1-0.8) / 0.20 = 1
(1-0.9) / 0.20 = 0.5
(1-1) / 0.20 = 0
This is the code I currently have but I a just trying to make it run in the opposite direction button.alpha = (1-x) / 0.20). How do I solve this and what type of math is this called?
To make it run the other way you can just subtract it from 1.
So...
button.alpha = 1 - (1 - x) / 0.2
I am trying to find the predicted weight of a person after t days of being on a diet and exercise program. An 180-pound man eats 2500 calories of food and burns 17.5 calories per pound of weight. The model I came up with for the resulting change in weight is this one
dw/dt = (2500/3500) - (17.5/3500)w, w(0) = 180.
How long will it take for the person to lose 20 pounds? What happens to the man's weight if they continue this program indefinitely?
Regarding the 3500 figure: "Common dieting wisdom says that we’ll lose one pound for every 3,500 calories we burn. Is that true?" - Huffington Post
Calculation using Mathematica
eqn = b'[t] == (2500 - 17.5 b[t])/3500;
sol = DSolve[{eqn, b[0] == 180}, b[t], t];
b[t_] := Evaluate[b[t] /. sol]
Quiet#Solve[b[t] == 160, t]
{{t -> 154.638}}
Limit[b[t], t -> Infinity]
{142.857}
20 pounds are lost after 154.638 days. Continued indefinitely weight plateaus at 142.857 pounds.
Plot[{b[t], 160}, {t, 0, 1000}, AxesLabel -> {"Days", "Pounds"}]
You can find details of the hand-calculation here: A mathematical diet model.
E.g.
db/dt = (2500 - 17.5 b[t])/3500
∴ db/dt + 0.005 b[t] = 2500/3500
∴ E^( 0.005 t) b[t] = (2500 E^( 0.005 t))/(3500*0.005) + k
k = b[0] - 2500/(3500*0.005)
∴ b[t] = 2500/(3500*0.005) + (180 - 2500/(3500*0.005)) E^( -0.005 t)
Check
when t = 154.638
b[t] = 2500/(3500*0.005) + (180 - 2500/(3500*0.005)) E^( -0.005 t) = 160
Note
This is for an accounting software, so the values are rounded to cents (2 decimal places).
Question
Given the final value invoice value of $4488.70 (we can call this value final), obtain the initial subtotal value (subtotal) in such a way that:
subtotal + round(0.07 * subtotal) - round(0.02 * subtotal) = final
For the case of final being $4488.70,
by directly doing division by 1.02 and obtaining $4400.6862745 (rounded to $4400.69)
For an invoice, this wouldn't tally because:
Subtotal 4400.69
VAT (7%) 308.05 ==> round(4400.69 * 0.07)
WHT (5%) 220.03 ==> round(4400.69 * 0.05)
==========
Final 4488.71 (4400.69 + 308.05 - 220.03)
That is not the wanted final value (off by 1 cent).
The better subtotal here should instead be 4400.68, but how do we obtain that algorithmically?
Subtotal 4400.68
VAT (7%) 308.05 ==> round(4400.68 * 0.07)
WHT (5%) 220.03 ==> round(4400.68 * 0.05)
==========
Final 4488.70 (4400.68 + 308.05 - 220.03)
Current proposed solution
Internally we are proposing doing a 3 passes by firstly obtain tentative subtotal = final/1.02, and work forward to see if we get the final intended value, if not, we try subtotal - 1 and ultimately subtotal + 1.
Pass 1: final/1.02
Pass 2: final/1.02 - 0.01
Pass 3: final/1.02 + 0.01
Is there a better, more efficient and still as reliable method as the proposed one?
What you want is not achievable in general. There might be some value final for which no such subtotal exists. (I'm too lazy to do a mathematical proof now, but I'm sure that some value can be found for which subtotal yields desiredFinal - 0.01 and subtotal + 0.01 yields desiredFinal + 0.01 due to the way rounding is performed).
There are two common ways to solve this:
subtotal = final/1.02, then calculate everything else, like you did in your first example:
Subtotal 4400.69
VAT (7%) 308.05 ==> round(4400.69 * 0.07)
WHT (5%) 220.03 ==> round(4400.69 * 0.05)
==========
Final 4488.71 (4400.69 + 308.05 - 220.03)
If there is a cent difference, add or remove it from subtotal and final. That means that VAT and WHT won't be precise w.r.t. subtotal.
Subtotal 4400.68 ==> one cent removed
VAT (7%) 308.05
WHT (5%) 220.03
==========
Final 4488.70 ==> one cent removed
Explicitly mention the rounding error:
Subtotal 4400.69
VAT (7%) 308.05
WHT (5%) 220.03
Rounding - 0.01
==========
Final 4488.70
Which one to choose depends on your local tax legislation.
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
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?