我有我的php代碼,但是它增加了20%的價值。它的格式不好,價格也很友善。 小數點後給出3位數字,而是2位數字。 這裏是我的代碼:將價格提高20%
$percentageChange = 20.00;
$sum_total = '1460.46';
//Our original number.
//Get 2.25% of 100.
$numberToAdd = ($sum_total/100) * $percentageChange;
//Finish it up with some simple addition
$total_price = $sum_total + $numberToAdd;
echo $total_price;
一個側面說明,'$ TOTAL_PRICE = $ sum_total * 1.2;'似乎更容易。 –
另外作爲一個方面說明,不要爲非js/html/css問題創建代碼片段,因爲我們無法運行代碼:) –
[PHP:顯示一個數字到2位小數]的可能重複( https://stackoverflow.com/questions/4483540/php-show-a-number-to-2-decimal-places) – Gunaseelan