Skip to content

Commit 48f0046

Browse files
committed
Revert "feat(Number): 添加 fileSize 方法的二进制前缀选项及相应测试 (#859)"
This reverts commit 51d88fe611d461b4ae10a2129ec97f35c34c85bd.
1 parent a93960f commit 48f0046

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

src/Number.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,12 @@ public static function currency(int|float $number, string $in = 'USD', ?string $
154154
*
155155
* @return string
156156
*/
157-
public static function fileSize(int|float $bytes, int $precision = 0, ?int $maxPrecision = null, bool $useBinaryPrefix = false)
157+
public static function fileSize(int|float $bytes, int $precision = 0, ?int $maxPrecision = null)
158158
{
159-
$base = $useBinaryPrefix ? 1024 : 1000;
160159
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
161160

162-
$units = $useBinaryPrefix
163-
? ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB', 'RiB', 'QiB']
164-
: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'RB', 'QB'];
165-
166-
for ($i = 0; ($bytes / $base) > 0.9 && ($i < count($units) - 1); ++$i) {
167-
$bytes /= $base;
161+
for ($i = 0; ($bytes / 1024) > 0.9 && ($i < count($units) - 1); ++$i) {
162+
$bytes /= 1024;
168163
}
169164

170165
return sprintf('%s %s', static::format($bytes, $precision, $maxPrecision), $units[$i]);

0 commit comments

Comments
 (0)