diff options
author | Simon Rettberg | 2024-05-29 14:52:56 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-05-29 14:52:56 +0200 |
commit | 6c2a2060866803fb117c963aac39af545e4c0236 (patch) | |
tree | a6d4b770bbbc2e5a098c749da30916097c5f8a92 /inc/util.inc.php | |
parent | [rebootcontrol] Fix the "bogus" array to string warning (diff) | |
download | slx-admin-6c2a2060866803fb117c963aac39af545e4c0236.tar.gz slx-admin-6c2a2060866803fb117c963aac39af545e4c0236.tar.xz slx-admin-6c2a2060866803fb117c963aac39af545e4c0236.zip |
[inc/Util] filesize: Fix calculating number of decimals to display
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r-- | inc/util.inc.php | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php index 267a3971..2568011b 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -95,14 +95,14 @@ class Util * Convert given number to human-readable file size string. * Will append Bytes, KiB, etc. depending on magnitude of number. * - * @param float|int $bytes numeric value of the filesize to make readable + * @param mixed $bytes numeric value of the filesize to make readable * @param int $decimals number of decimals to show, -1 for automatic * @param int $shift how many units to skip, i.e. if you pass in KiB or MiB * @return string human-readable string representing the given file size */ public static function readableFileSize($bytes, int $decimals = -1, int $shift = 0): string { - // round doesn't reliably work for large floats, pick workaround depending on OS + // round doesn't reliably work for large floats, and we use strlen either way $bytes = sprintf('%u', $bytes); static $sz = array('Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'); $factor = (int)floor((strlen($bytes) - 1) / 3); @@ -111,7 +111,7 @@ class Util } else { $bytes /= 1024 ** $factor; if ($decimals === -1) { - $decimals = 2 - strlen((string)floor($bytes)) - 1; + $decimals = 3 - strlen((string)floor($bytes)); } } return Dictionary::number((float)$bytes, $decimals) . "\xe2\x80\x89" . ($sz[$factor + $shift] ?? '#>PiB#'); |