From 5a19024bec3244b548ef83319ce9b022f3eaae4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 2 Mar 2023 23:39:12 +0100 Subject: [PATCH] Use 10 based prefixes for byte sizes instead of 2-based This way we are consistent with the way symfony interprets the prefixes --- src/Services/Attachments/AttachmentManager.php | 4 ++-- src/Twig/FormatExtension.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Services/Attachments/AttachmentManager.php b/src/Services/Attachments/AttachmentManager.php index f789d3de..bddea30b 100644 --- a/src/Services/Attachments/AttachmentManager.php +++ b/src/Services/Attachments/AttachmentManager.php @@ -160,7 +160,7 @@ class AttachmentManager $sz = 'BKMGTP'; $factor = (int) floor((strlen((string) $bytes) - 1) / 3); - - return sprintf("%.{$decimals}f", $bytes / 1024 ** $factor).@$sz[$factor]; + //Use real (10 based) SI prefixes + return sprintf("%.{$decimals}f", $bytes / 1000 ** $factor).@$sz[$factor]; } } diff --git a/src/Twig/FormatExtension.php b/src/Twig/FormatExtension.php index 87c906b1..36a8dad4 100644 --- a/src/Twig/FormatExtension.php +++ b/src/Twig/FormatExtension.php @@ -119,6 +119,7 @@ final class FormatExtension extends AbstractExtension { $size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; $factor = floor((strlen((string) $bytes) - 1) / 3); - return sprintf("%.{$precision}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor]; + //We use the real (10 based) SI prefix here + return sprintf("%.{$precision}f", $bytes / (1000 ** $factor)) . ' ' . @$size[$factor]; } }