我有最難倒的時間試圖自動計算稅收在PHP中。這是我到目前爲止有:計算稅額總額再次PHP設置變量
<?php
// Formats a number so it appears as such : 55.12, instead of 55.12354
function invoiceNumFormat($number){
return number_format($number, 2);
}
$tax_rate = 7.5; //Sets Tax Rate
// Retrieves Subtotal, utilitzes NumFormat function to round to hundredths place
$invoice_subtotal = isset($invoice['invoice_subtotal']) ? invoiceNumFormat($invoice['invoice_subtotal']): 0;
//Multiplies subtotal against tax rate to retrieve $tax_amount
$tax_amount = invoiceNumFormat($invoice_subtotal*$tax_rate/100);
// Shows Grand Total(subtotal + tax)
$invoice_totalled = $invoice_subtotal + $tax_amount;
//Displays Totals
<span>'.$invoice_subtotal.'</span>
<span>'.$tax_amount.'</span>
<span>'.$invoice_totalled.'</span>
?>
我有一個小計的輸出顯示「3116.88」,這是正確的,但稅收表現爲量。」 32" 和總計是‘3.23’ 。任何人都可以告訴我哪裏出了問題?
我試過你的代碼$ invoice_subtotal = 3116.88; //硬編碼的價值,這導致我罰款,總計:3116.88,稅:233.77,總計:3350.65。所以我認爲,$ invoice_subtotal變量下有一些錯誤的值。 – ameenulla0007
@ ameenulla0007排除了一些錯誤,只要我拿出invoiceNumFormat函數,就會發現所有總計都會出現FINE。現在的問題是,我仍然需要把這一美元的數額... – Steven
美元的金額!你可以清楚這個請.. – ameenulla0007