计算发票

发布于 2024-10-13 01:02:43 字数 484 浏览 1 评论 0原文

我需要计算方面的帮助:

我需要这样做:

Item ---- Qty ( 2  )  --- Rate ( $2  )   = Total (  $4  )
Item ---- Qty ( 3  )  --- Rate ( $3  )   = Total (  $9  )

SUBTOTAL  = $13
SALES TAX (0.07) or (0.7%) = $0.91
TOTAL = $13.91

用代码。

我的伪代码是:

Multiply qty * rate and input in total

subtotal = sum of item totals

sales tax = 0.07 * subtotal 

total = sum of subtotal and sales tax

我刚才解释的函数有任何特定的或预制的代码吗?

有什么想法吗?

I need help with a calculation:

I need to do this:

Item ---- Qty ( 2  )  --- Rate ( $2  )   = Total (  $4  )
Item ---- Qty ( 3  )  --- Rate ( $3  )   = Total (  $9  )

SUBTOTAL  = $13
SALES TAX (0.07) or (0.7%) = $0.91
TOTAL = $13.91

in code.

my pseudocode is:

Multiply qty * rate and input in total

subtotal = sum of item totals

sales tax = 0.07 * subtotal 

total = sum of subtotal and sales tax

Any specific or pre-made code for the function I have just explained?

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2024-10-20 01:02:43

我想如果你想让一些东西可重复使用,它会是这样的:

var items = []; // array that contains all your items

function Item(quantity, rate) { // Item constructor
    this.quantity = quantity;
    this.rate = rate;
    this.total = quantity * rate;
}

items.push(new Item(2, 4), new Item(3, 9)); // creates 2 items and add them to the array

// Processing through every items to get the total
var total = 0;
for (var i = 0; i < items.length - 1; i++) {
    total += items[i].total;
}

total += total * 0.07; // calculates taxes

I guess if you want to make something re-usable it would look as such :

var items = []; // array that contains all your items

function Item(quantity, rate) { // Item constructor
    this.quantity = quantity;
    this.rate = rate;
    this.total = quantity * rate;
}

items.push(new Item(2, 4), new Item(3, 9)); // creates 2 items and add them to the array

// Processing through every items to get the total
var total = 0;
for (var i = 0; i < items.length - 1; i++) {
    total += items[i].total;
}

total += total * 0.07; // calculates taxes
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文