From eb06ea5463286370b09ddb17ef4d1f4291efe752 Mon Sep 17 00:00:00 2001 From: ralf Date: Sun, 11 Feb 2024 10:53:11 +0200 Subject: [PATCH] allow to specify number of digits for Vfs:hsize() --- api/src/Vfs.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/src/Vfs.php b/api/src/Vfs.php index 820cc6ffdd..1809cf7b08 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -1108,9 +1108,10 @@ class Vfs extends Vfs\Base * Human readable size values in k, M or G * * @param int $size + * @param int? $digits default: 2 * @return string */ - static function hsize($size) + static function hsize($size, int $digits=2) { if($size < 1024) { @@ -1118,13 +1119,13 @@ class Vfs extends Vfs\Base } if($size < 1024 * 1024) { - return sprintf('%3.2fk', (float)$size / 1024); + return sprintf("%0.{$digits}fk", (float)$size / 1024); } if($size < 1024 * 1024 * 1024) { - return sprintf('%3.4fM', (float)$size / (1024 * 1024)); + return sprintf("%0.{$digits}fM", (float)$size / (1024 * 1024)); } - return sprintf('%3.4fG', (float)$size / (1024 * 1024 * 1024)); + return sprintf("%0.{$digits}fG", (float)$size / (1024 * 1024 * 1024)); } /**