Use 10 based prefixes for byte sizes instead of 2-based

This way we are consistent with the way symfony interprets the prefixes
This commit is contained in:
Jan Böhmer 2023-03-02 23:39:12 +01:00
parent e0635f7ead
commit 5a19024bec
2 changed files with 4 additions and 3 deletions

View file

@ -160,7 +160,7 @@ class AttachmentManager
$sz = 'BKMGTP'; $sz = 'BKMGTP';
$factor = (int) floor((strlen((string) $bytes) - 1) / 3); $factor = (int) floor((strlen((string) $bytes) - 1) / 3);
//Use real (10 based) SI prefixes
return sprintf("%.{$decimals}f", $bytes / 1024 ** $factor).@$sz[$factor]; return sprintf("%.{$decimals}f", $bytes / 1000 ** $factor).@$sz[$factor];
} }
} }

View file

@ -119,6 +119,7 @@ final class FormatExtension extends AbstractExtension
{ {
$size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; $size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$factor = floor((strlen((string) $bytes) - 1) / 3); $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];
} }
} }