[Android] Add readableSize String formatting method

Geoffrey Métais git at videolan.org
Mon Jan 18 11:09:21 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan 18 11:07:48 2016 +0100| [b7694f177c682d5490f2b06e5906c83d2aa4ae5d] | committer: Geoffrey Métais

Add readableSize String formatting method

> https://code.videolan.org/videolan/vlc-android/commit/b7694f177c682d5490f2b06e5906c83d2aa4ae5d
---

 vlc-android/src/org/videolan/vlc/util/Strings.java | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/util/Strings.java b/vlc-android/src/org/videolan/vlc/util/Strings.java
index 9af84b7..fc8718a 100644
--- a/vlc-android/src/org/videolan/vlc/util/Strings.java
+++ b/vlc-android/src/org/videolan/vlc/util/Strings.java
@@ -122,6 +122,13 @@ public class Strings {
         return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
     }
 
+    public static String readableSize(long size) {
+        if(size <= 0) return "0";
+        final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
+        int digitGroups = (int) (Math.log10(size)/Math.log10(1000));
+        return new DecimalFormat("#,##0.#").format(size/Math.pow(1000, digitGroups)) + " " + units[digitGroups];
+    }
+
     public static String removeFileProtocole(String path){
         if (path == null)
             return null;



More information about the Android mailing list