例子,php四舍五入函数代码。
<?php
function round_pad_zero($num, $precision)
{
if ($precision < 1) {
return round($num, 0);
}
$r_num = round($num, $precision);
$num_arr = explode('.', "$r_num");
if (count($num_arr) == 1) {
return "$r_num" . '.' . str_repeat('0', $precision);
}
$point_str = "$num_arr[1]";
if (strlen($point_str) < $precision) {
$point_str = str_pad($point_str, $precision, '0');
}
return $num_arr[0] . '.' . $point_str;
}
//示例
echo round_pad_zero(3223342.506, 4);