简体   繁体   English

为服务/产品添加百分比的正确方法是什么?

[英]What is the right way to add percentages to a service/product?

I have to add up the service charge(10%) plus VAT(8%) to a service, and I'm not sure the right way to increase a number by percentages. 我必须将一项服务的服务费(10%)加增值税(8%)加起来,但我不确定增加百分比的正确方法。

For example: The service costs $1000 and I need to add to it 10% plus 8%. 例如:服务费用为$ 1000,我需要在此添加10%加8%。 I'm struggling with three different ways to achieve that. 我正在努力通过三种不同的方法来实现这一目标。 Which way is the right one? 正确的方法是哪一种?

var service_charge = 10; // percent
var vat = 8; // percent
var price = 1000;

// OPTION 1
var tmp1 = price * (service_charge / 100);
var tmp2 = price * (vat / 100);
var total_1 = price + tmp1 + tmp2;

// OPTION 2
var tmp3 = price * (service_charge / 100);
var sub_total = price + tmp3;
var tmp4 = sub_total * (vat / 100);
var total_2 = sub_total + tmp4;

// OPTION 3
var tmp5 = price * ((service_charge + vat) / 100);
var total_3 = price + tmp5;

console.log(total_1);
console.log(total_2);
console.log(total_3);

https://jsbin.com/povama/edit?js,console https://jsbin.com/povama/edit?js,控制台

I think "option 2" is the right one, but I really want to be sure. 我认为“选项2”是正确的选择,但我真的想确定。

If VAT is to be applied after service charge, option 2 is the good one. 如果要在服务费后加上增值税,则选择2是不错的选择。 If you want to summarize it in one single line it would be something like this: 如果要在一行中对其进行汇总,则可能是这样的:

var total = (price*(1+(service_charge/100)))*(1+(vat/100));

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

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