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;
}
var_dump(round_pad_zero(0.6,3));// 结果:string(5) "0.600"
正在学习Go语言的PHP程序员。