-
-
/**
- * 小数位四舍五入并补零
- * by bbs.it-home.org
- */
- function round_pad_zero($num, $precision)
- {
- if ($precision 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) $point_str = str_pad($point_str, $precision, '0');
- }
- return $num_arr[0] . '.' . $point_str;
- }
- //调用示例
- echo round_pad_zero(3223342.506, 4);
复制代码
|