= count($units)) { $index = count($units) - 1; } $size = round(pow(1024, $base - $index), $precision); return $size . ' ' . $units[$index]; } /** * 格式化执行时间 * * @param float $seconds 秒数 * @return string 格式化后的时间 */ public static function formatExecutionTime(float $seconds): string { if ($seconds < 1) { return round($seconds * 1000) . ' ms'; } elseif ($seconds < 60) { return round($seconds, 2) . ' 秒'; } elseif ($seconds < 3600) { $minutes = floor($seconds / 60); $remainingSeconds = $seconds % 60; return $minutes . ' 分 ' . round($remainingSeconds) . ' 秒'; } else { $hours = floor($seconds / 3600); $minutes = floor(($seconds % 3600) / 60); return $hours . ' 小时 ' . $minutes . ' 分'; } } /** * 格式化数字 * * @param int|float $number 数字 * @return string 格式化后的数字 */ public static function formatNumber($number): string { if ($number >= 1000000000) { return round($number / 1000000000, 1) . 'B'; } elseif ($number >= 1000000) { return round($number / 1000000, 1) . 'M'; } elseif ($number >= 1000) { return round($number / 1000, 1) . 'K'; } else { return number_format($number); } } /** * 格式化百分比 * * @param float $value 值 * @param float $total 总数 * @param int $precision 精度 * @return string 格式化后的百分比 */ public static function formatPercentage(float $value, float $total, int $precision = 2): string { if ($total == 0) { return '0%'; } $percentage = ($value / $total) * 100; return round($percentage, $precision) . '%'; } /** * 格式化进度条HTML * * @param float $progress 进度值 (0-100) * @param string $color 颜色类型 * @return string HTML字符串 */ public static function formatProgressBar(float $progress, string $color = 'primary'): string { $progress = max(0, min(100, $progress)); return "