Android Kotlin Convert File Size to Human Readable kB,MB,GB etc

masterjosh
by
masterjosh
Jan 10, 2019
Android Kotlin Convert File Size to Human Readable kB,MB,GB etc

Hi Dev,

this pretty little snippet am about to share, will allow you to convert file size in bytes to human readable format...

Fun/method code named fileSize


fun fileSize(size2:Int):String {
        val size = size2.toLong()
        if (size <= 0) return "0"
        val units = arrayOf("B", "kB", "MB", "GB", "TB")
        val digitGroups = (Math.log10(size.toDouble()) / Math.log10(1024.0)).toInt()
        return DecimalFormat("#,##0.#").format(size / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
    }

are you have any problem using this code ?

i will be happy to help via comment section 

Happy Coding!




Comments (19969)
Eyepaync
by
Eyepaync
Jul 29, 2019

<a href="https://cafergot1.com/">cafergot medication</a>

Eyepaync
by
Eyepaync
Jul 30, 2019

<a href="https://cafergot1.com/">cafergot & internet pharmacy</a>

Eyepaync
by
Eyepaync
Aug 01, 2019

<a href="https://cafergot1.com/">generic cafergot</a>

Eyepaync
by
Eyepaync
Aug 02, 2019

<a href="https://cafergot1.com/">cafergot tablets</a>

Eyepaync
by
Eyepaync
Aug 04, 2019

<a href="https://cafergot1.com/">generic cafergot</a>

Eyepaync
by
Eyepaync
Aug 05, 2019

<a href="https://cafergot1.com/">buy cafergot online</a>

Eyepaync
by
Eyepaync
Aug 06, 2019

<a href="https://cafergot1.com/">ordering cafegot</a>

Eyepaync
by
Eyepaync
Aug 08, 2019

<a href="https://cafergot1.com/">generic cafergot</a>

canadian online pharmacies
by
canadian online pharmacies
Aug 08, 2019

<a href="http://canadianpharmaciesoffer.com/">reputable mexican pharmacies online</a>

http://canadianpharmaciesoffer.com/

<a href=http://canadianpharmaciesoffer.com/>online pharmacy with no prescription</a>

Eyepaync
by
Eyepaync
Aug 09, 2019

<a href="https://cafergot1.com/">cafergot</a>

Add Comment