From 22bb94fc1cde109b8a170e1c12fd98f3fe1c7154 Mon Sep 17 00:00:00 2001
From: Davide Depau <davide@depau.eu>
Date: Fri, 17 Aug 2018 22:10:02 +0200
Subject: [PATCH] Fix HR size formatting issues

---
 .../java/eu/depau/etchdroid/kotlin_exts/NumberToSizeString.kt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/eu/depau/etchdroid/kotlin_exts/NumberToSizeString.kt b/app/src/main/java/eu/depau/etchdroid/kotlin_exts/NumberToSizeString.kt
index 9dd789e..c259192 100644
--- a/app/src/main/java/eu/depau/etchdroid/kotlin_exts/NumberToSizeString.kt
+++ b/app/src/main/java/eu/depau/etchdroid/kotlin_exts/NumberToSizeString.kt
@@ -4,10 +4,10 @@ package eu.depau.etchdroid.kotlin_exts
 
 private fun <T> humanReadableByteCount(bytes: T, si: Boolean = true): String where T : Comparable<T>, T : Number {
     val unit: Long = if (si) 1000 else 1024
-    if (bytes.toLong() < unit) return String.format("%.2f B", bytes)
+    if (bytes.toLong() < unit) return String.format("%.1f B", bytes.toDouble())
     val exp = (Math.log(bytes.toDouble()) / Math.log(unit.toDouble())).toInt()
     val pre = (if (si) "kMGTPE" else "KMGTPE")[exp - 1] + if (si) "" else "i"
-    return String.format("%.2f %sB", bytes.toDouble() / Math.pow(unit.toDouble(), exp.toDouble()), pre)
+    return String.format("%.1f %sB", bytes.toDouble() / Math.pow(unit.toDouble(), exp.toDouble()), pre)
 }
 
 fun Long.toHRSize(si: Boolean = true) = humanReadableByteCount(this, si)