mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-17 04:10:39 +01:00
adding the new helper extension for formatting file size
This commit is contained in:
parent
a246ca514f
commit
6dd545e4b5
@ -58,7 +58,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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:RootTools:df729dcb13'
|
||||||
implementation 'com.github.Stericson:RootShell:1.6'
|
implementation 'com.github.Stericson:RootShell:1.6'
|
||||||
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
||||||
|
@ -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]}"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user