diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6a2b1..d051d01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ CHANGELOG for 1.x =================== +## v1.0.3 - (2024-01-11) + +### Fix + +- `MathUtils::formatBytes` : Use 1000 instead of 1024 for calculate + ## v1.0.2 - (2024-01-11) ### Added diff --git a/src/Utils/MathUtils.php b/src/Utils/MathUtils.php index 14a7856..ef6edfe 100644 --- a/src/Utils/MathUtils.php +++ b/src/Utils/MathUtils.php @@ -24,10 +24,10 @@ public static function calculatePercentage(?float $partial, float $total, ?int $ */ public static function formatBytes(float $size, int $precision = 2): string { - $base = log($size, 1024); + $base = log($size, 1000); $suffixes = ['B', 'KB', 'MB', 'GB', 'TB']; $floor = floor($base); - return round(pow(1024, $base - $floor), $precision) . ' ' . $suffixes[$floor]; + return round(pow(1000, $base - $floor), $precision) . ' ' . $suffixes[$floor]; } } diff --git a/tests/Utils/MathUtilsTest.php b/tests/Utils/MathUtilsTest.php index 13e015a..a73c067 100644 --- a/tests/Utils/MathUtilsTest.php +++ b/tests/Utils/MathUtilsTest.php @@ -62,10 +62,10 @@ public function formatBytesProvider(): array // precision null, ], - '1.26 KB' => ['1.26 KB', 1290, null], - '536.918 MB' => ['536.918 MB', 562999000, 3], - '880 GB' => ['880 GB', 945000000000, 0], - '382.86 TB' => ['382.86 TB', 420956000000000, 2], + '1.29 KB' => ['1.29 KB', 1290, null], + '562.999 MB' => ['562.999 MB', 562999000, 3], + '945 GB' => ['945 GB', 945000000000, 0], + '420.96 TB' => ['420.96 TB', 420956000000000, 2], ]; } }