From 852c70198bef1fdde918b0f51a0c19d9abd1cb46 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 31 Jul 2026 19:27:13 +0800 Subject: [PATCH] refactor(package): replace manual MB calculation with format function - Replace round() calculation with formatMegabytes() function call - Add new formatMegabytes() utility function for consistent formatting - Use number_format() for precise decimal handling in MB conversion - Centralize byte to MB conversion logic in single reusable function --- package.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/package.php b/package.php index 383d0f30..40aaa165 100755 --- a/package.php +++ b/package.php @@ -501,7 +501,7 @@ echo "[8/8] 清理临时文件...\n"; // 获取文件大小 $packageSize = filesize($outputFile); -$packageSizeMB = round($packageSize / 1024 / 1024, 2); +$packageSizeMB = formatMegabytes($packageSize); echo "临时目录: {$topLevelDir}\n"; removeDirectory($topLevelDir); @@ -742,10 +742,15 @@ function packageUnixLike(): void } $cleanupArchive = false; - $sizeMb = round(filesize($outputFile) / 1024 / 1024, 2); + $sizeMb = formatMegabytes(filesize($outputFile)); echo "Package successful: {$outputFile} ({$sizeMb} MB)\n"; } +function formatMegabytes(int $bytes): string +{ + return number_format($bytes / 1024 / 1024, 3, '.', ''); +} + /** * 递归复制目录 * @param string $src 源目录