gpt4 book ai didi

javascript - 如何使用 jQuery 对发票应用税收、折扣

转载 作者:行者123 更新时间:2023-11-28 16:36:54 28 4
gpt4 key购买 nike

如何应用税收、小计折扣以及计算总计?

我的这些段落具有以下 ID

<p id="subtotal">15000</p>
<p id="tax">10</p> // In percentage
<p id="discount">1000</p>
<p id="grandtotal"></p> // Grandtotal will be calculated and displayed here using jquery

总金额为 15000 +(1500//税)-(1000//折扣)= 15500

如何使用 jQuery 计算此值?

最佳答案

var subtotal = parseFloat( $('#subtotal').text());
var taxRate = parseFloat( $('#tax').text());
var disc = parseFloat( $('#discount').text());

var taxAmount = subtotal * (taxRate/parseFloat("100")); //15000 * .1

var yourGrandTotal = subtotal + (taxAmount) - (disc);

//update div with the val
$('#grandtotal').text(yourGrandTotal);

关于javascript - 如何使用 jQuery 对发票应用税收、折扣,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3506863/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com