我有我的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