Merge pull request #4373 from kiwix/Fixes#4368

Fixed: File size unit / calculation differs from Kiwix-Server.
This commit is contained in:
Kelson 2025-08-13 11:38:03 +02:00 committed by GitHub
commit bd7228354f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -20,7 +20,7 @@
<ID>MagicNumber:DownloaderModule.kt$DownloaderModule$5</ID>
<ID>MagicNumber:FileUtils.kt$FileUtils$3</ID>
<ID>MagicNumber:JNIInitialiser.kt$JNIInitialiser$1024</ID>
<ID>MagicNumber:Byte.kt$Byte$1024.0</ID>
<ID>MagicNumber:Byte.kt$Byte$1000.0</ID>
<ID>MagicNumber:MainMenu.kt$MainMenu$99</ID>
<ID>MagicNumber:ReaderMenuState.kt$ReaderMenuState$99</ID>
<ID>MagicNumber:OnSwipeTouchListener.kt$OnSwipeTouchListener.GestureListener$100</ID>

View File

@ -27,9 +27,9 @@ value class Byte(private val byteString: String?) {
val humanReadable
get() = byteString?.toLongOrNull()?.let {
val units = arrayOf("B", "KB", "MB", "GB", "TB")
val conversion = (log10(it.toDouble()) / log10(1024.0)).toInt()
DecimalFormat("#,##0.#")
.format(it / 1024.0.pow(conversion.toDouble())) +
val conversion = (log10(it.toDouble()) / log10(1000.0)).toInt()
DecimalFormat("#,##0.##")
.format(it / 1000.0.pow(conversion.toDouble())) +
" " +
units[conversion]
}.orEmpty()