这是我写的php,它与一些wordpress函数略有混合。
但是,我希望将所有值四舍五入到一个小数位,但我无法弄清楚如何操作 - 下面的php非常基本 - 但我无法计算小数的下一步。
<?php
$one_decimal_place = number_format(2.10, 1);
// AVERAGE DRINK COSTS
$li2 = get_field('average_drinks_spenditure_per_night');
$li3 = ($li2 * 28) * 2.1;
$li4 = $li3 * 3;
// HOUSING COSTS
$li22 = (get_field('average_housing_costs_per_week') * 4 );
$li33 = $li22 * 12;
$li44 = $li33 * 3;
// SHOPPING COSTS
$li222 = (get_field('average_shopping_trip_price') * 2.25 );
$li333 = $li222 * 12;
$li444 = $li333 * 3;
// TUITION FEES
$tuitionClass = (get_field('tuition_fees') /28 );
$tuitionTotal = (get_field('tuition_fees') * 3 );
// PHP TCE
$totalcost2 = $li444 + $tuitionTotal;
$totalcost3 = $li4 + $li44;
$totalcost = $totalcost2 + $totalcost3;
?>
答案 0 :(得分:1)
您已尝试过功能round
??
$test = 15.321321321;
echo round($test,1);
结果:15.3;
如果你不像我的朋友说的那样想要使用这个:
$test = 15.321321321;
echo round($test,1,PHP_ROUND_HALF_UP);
结果:15.4