简体   繁体   English

如何从javascript中的总量和价值中找出增值税

[英]how to find out the vat from total amount and percetage value in javascript

This following code for get back to vat value from percentage value and amount value using java script but its not accuracy. 以下代码使用Java脚本从百分比值和金额值返回增值税值,但不准确。

var vat=((25*100)/447);
vat=vat.toFixed(1);

OK, to help, you need to specify the details you are working with. OK,要提供帮助,您需要指定正在使用的详细信息。 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). 因此,更改增值税税率以匹配您的税率,我猜这是25%(0.25)。

Using "toFixed(1)" will ensure the value is fixed to 1 decimal place - usually you need two decimal places for VAT. 使用“ toFixed(1)”将确保该值固定为1个小数位-通常,您需要为增值税加上两个小数位。 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. 将值保存在数据库中时,应将每个值四舍五入到小数点后三位,无论是大桶,百分比还是总金额。要将其呈现给用户/客户,您可以将其四舍五入到小数点后一位或二位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM