adding the new helper extension for formatting file size

This commit is contained in:
tibbi 2021-10-11 18:20:05 +02:00
parent a246ca514f
commit 6dd545e4b5
2 changed files with 15 additions and 1 deletions

View File

@ -58,7 +58,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:69346a62e0'
implementation 'com.github.SimpleMobileTools:Simple-Commons:cad50847e3'
implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.github.Stericson:RootShell:1.6'
implementation 'com.alexvasilkov:gesture-views:2.5.2'

View File

@ -0,0 +1,14 @@
package com.simplemobiletools.filemanager.pro.extensions
import java.text.DecimalFormat
// use 1000 instead of 1024 at dividing
fun Long.formatSizeThousand(): String {
if (this <= 0) {
return "0 B"
}
val units = arrayOf("B", "kB", "MB", "GB", "TB")
val digitGroups = (Math.log10(toDouble()) / Math.log10(1000.0)).toInt()
return "${DecimalFormat("#,##0.#").format(this / Math.pow(1000.0, digitGroups.toDouble()))} ${units[digitGroups]}"
}