Javascript计算从parseFloat值总计支付的19%的税

I need to calculate the total taxes from the total price to pay including the taxes, the tax rate is 19% so the correct calculation is for example

total to pay = 1000 the taxes must be 160

Why? Because 840 + 19% gives you the total price to pay = 1000 so you know the taxes of 1000 including taxes are not 190 with 19% rate but 160.

To calculate it with autofill the input I am using javascript like this to autofill many inputs

totaltaxes.value = parseInt((parseFloat(totaltopay.value)*19)/100);}

The problem is that I keep getting 190 as result of the 19% taxes and it must be 160.

Anyone have a formula to do this or idea how to calculate it? It is the 19% of the total price to pay including the taxes in the total price

This will give you the total tax :

parseInt(totaltopay.value)*0.19/1.19

This is more of a math problem than a javascript problem.

But, here's the solution anyway:

Your totaltopay value includes the tax, hence it is 1+(tax_percentage/100) times more than the amount to be paid.

You need to be doing parseInt(totaltopay.value/1.19) to get the amount to be paid.

Thus, the tax amount would be

(totaltopay.value - (totaltopay.value/1.19) = (totaltopay.value*0.19/1.19)

That is, totaltaxes.value = parseInt((parseFloat(totaltopay.value)*19)/119);