最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to find out the vat from total amount and percetage value in javascript - Stack Overflow

programmeradmin6浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 7

OK, 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.

发布评论

评论列表(0)

  1. 暂无评论