你好,我怎么把下面的代码四舍五入到小数点后两位呢?
echo
"<div class='quote-results-result'>ex VAT £" .
((($_POST['qtylitres'] * $price ['Price']) + $fuelmargin['margin']) / 1.2) .
"</div>"我需要四舍五入的价格位的php新手。
发布于 2012-07-13 19:46:09
round($VARIABLE_NAME,2); //将变量四舍五入到小数点后两位
发布于 2012-07-13 19:43:47
如下所示使用number_format函数:
$number = 1234.56789
$new_number = number_format($number, 2, '.', '');
echo $new_number;
Output: 1234.57发布于 2012-07-13 19:44:43
使用php手册中的round函数
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06https://stackoverflow.com/questions/11469814
复制相似问题