This following code for get back to vat value from percentage value and amount value using java script but its not accuracy.
var vat=((25*100)/447);
vat=vat.toFixed(1);
This following code for get back to vat value from percentage value and amount value using java script but its not accuracy.
var vat=((25*100)/447);
vat=vat.toFixed(1);
Share
Improve this question
asked Jan 29, 2013 at 12:20
ishwarishwar
4447 silver badges20 bronze badges
2 Answers
Reset to default 7OK, to help, you need to specify the details you are working with. What is the VAT rate? Are you working from the gross value (includes the VAT), or the nett value (excludes the VAT).
var nVatRate = 0.2;// This is the rate of VAT in the UK at present, 20%
function VatAmountFromGross(nGrossAmount){
return nGrossAmount / (1 + (1 / nVatRate));
}
function VatAmountFromNet(nNetAmount){
return nNetAmount * (1 + nVatRate);
}
So, change the VAT rate to match yours, which I am guessing is 25% (0.25).
Using "toFixed(1)" will ensure the value is fixed to 1 decimal place - usually you need two decimal places for VAT. You will also have rounding issues if you are summing values, and these cannot be helped.
Instead of this:
var vat=((25*100)/447);
vat=vat.toFixed(1);
You should be using exact total amount:
var vat=((24.585*100)/447);
vat=vat.toFixed(3);
What you should do while saving the values in the database is round of every value to three decimal, be it vat, percentage or total amount..and to present it to the user/client you can round it off to one or two decimal places.