+ 2

[Challenge: Reverse Percentage]

Okay, So you have a price of 100$ and need to add 19% tax. Piece of cake. ==> 119 The challenge: The Price of the item is 100$ including tax. How do you calculate the value that will become 100 when added 19% tax?! Your method should take 2 arguments as the parameters: one for the desired value (including tax) and one for the % and return the base price w/o tax which will then result in the desired value if you just add the tax %. It should be precise!

9th Nov 2017, 3:27 PM
David
David - avatar
11 Respostas
+ 11
JavaScript: var a = prompt("").split(" "); alert((100 * (a[0] - 0)) / (100 + (a[1] - 0)));
9th Nov 2017, 3:34 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 3
money=int(input("How much money? ")) print(money) taxadd=int(input("What percent added? ")) print(taxadd) plus=money/100*taxadd print(money+plus)
9th Nov 2017, 4:18 PM
Max S
+ 1
Beside the input: good idea. But not very user friendly 😜 and wrong as it returns a number which needs to be multiplied by 100 to get the basic w/of tax
9th Nov 2017, 3:44 PM
David
David - avatar
+ 1
Wouldn't that be 119 instead of 84,03?
9th Nov 2017, 4:24 PM
David
David - avatar
+ 1
You mean you want the code to generate a function that calculates the result of this formula: val/(100+proc)*100 ?
9th Nov 2017, 6:53 PM
Alex Dobrin
Alex Dobrin - avatar
+ 1
Even if you buy 1,000,000 you get a difference of 0.0001, so it is irrelevant. But if you don't round that value the end result of the total sales might be close to reality because some transactions will cancel other transactions (gain on same, lose on some). Plus, any accountant will ask you to round up the VAT not the price just so they think they are on the safe side. :)
10th Nov 2017, 10:32 AM
Alex Dobrin
Alex Dobrin - avatar
0
Basically yes and no. Well actually just no. It would be + something, not *. But: imagine Val is 100 and proc is 10. We are searching for a number that will become 100 when you add 10%. Your code: 100/(110)=90,9090909 × 100 != 100......
10th Nov 2017, 1:15 AM
David
David - avatar
0
And if you add 10% of 90.9090909 to 90.9090909 you get 100. How is that not answering your original question?
10th Nov 2017, 7:12 AM
Alex Dobrin
Alex Dobrin - avatar
0
That would nearly answer it. Except it will be 99.9999999999 ;-)
10th Nov 2017, 7:24 AM
David
David - avatar
0
Of course. And all the prices in the stores have 10 decimal points. :)
10th Nov 2017, 7:32 AM
Alex Dobrin
Alex Dobrin - avatar
0
No, but if you buy 100 might matter. The trick is to round the first result, in this example you get 90,91 if you than add 9,09 you are back to 100
10th Nov 2017, 7:48 AM
David
David - avatar