diff --git a/app/Module/Base.php b/app/Module/Base.php index 801922714..e3e7928b7 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2818,14 +2818,17 @@ class Base /** * 字节转格式 - * @param $bytes + * @param int|float $bytes * @return string */ - public static function readableBytes($bytes) + public static function readableBytes(int|float $bytes): string { - $i = floor(log($bytes) / log(1024)); + if ($bytes <= 0) { + return '0 B'; + } + $i = (int) floor(log($bytes) / log(1024)); $sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - return sprintf('%.02F', $bytes / pow(1024, $i)) * 1 . ' ' . $sizes[$i]; + return (string) ((float) sprintf('%.02F', $bytes / pow(1024, $i))) . ' ' . $sizes[$i]; } /**