mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	adding the new helper extension for formatting file size
This commit is contained in:
		| @@ -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' | ||||
|   | ||||
| @@ -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]}" | ||||
| } | ||||
		Reference in New Issue
	
	Block a user