X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/8fd22c9ade887e18e01dafd8a24842f6cfdc93ab..00480c926f002a6bbc7ebd742e8450bc1b1a6f9d:/format.inc.php diff --git a/format.inc.php b/format.inc.php index 10908f3..35ecebb 100644 --- a/format.inc.php +++ b/format.inc.php @@ -14,3 +14,15 @@ function showdate($parts) ])); } +function showsize($bytes) +{ + $units = ['', 'k', 'M', 'G', 'T']; + $log = strlen($bytes) - 1; + $order = floor($log / 3); + if (!isset($units[$order])) return $bytes; + return implode(' ', [ + number_format($bytes / (1000 ** $order), $log % 3 ? 0 : 1, ',', ''), + $units[$order], + ]); +} +