//格式化为:{n}GB{n}MB{n}KB的样式 function formatByteSize($bytes) { $format = $bytes . 'B'; foreach (array(1 => 'KB', 2 => 'MB', 3 => 'GB') as $exp => $unit) { $base = pow(1024, $exp); if ($bytes > $base) { $format = number_format($bytes / $base, 2) . $unit; continue; } else { break; } } return $format; } //格式化为:{n}天{n}小时{n}分{n}秒的样式 function formatSecondTime($time) { $format = ''; $units = array('天' => 86400, '小时' => 3600, '分' => 60, '秒' => 1); foreach ($units as $unit => $base) { if ($base > 0) { $nowUnitValue = intval($time / $base); $format .= $nowUnitValue.$unit; $time = $time - ($nowUnitValue * $base); } } return $format; } //格式化为:{n}%的样式 function formatPercent($numerator, $denominator) { return $denominator ? number_format(($numerator / $denominator) * 100, 2).'%' : 0; }