|
@@ -22,6 +22,7 @@
|
|
|
|
|
|
package com.owncloud.android.utils;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.IDN;
|
|
|
import java.text.DateFormat;
|
|
|
import java.util.Arrays;
|
|
@@ -55,6 +56,7 @@ public class DisplayUtils {
|
|
|
//private static String TAG = DisplayUtils.class.getSimpleName();
|
|
|
|
|
|
private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
|
|
+ private static final int[] sizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 };
|
|
|
|
|
|
private static HashMap<String, String> mimeType2HUmanReadable;
|
|
|
static {
|
|
@@ -114,7 +116,11 @@ public class DisplayUtils {
|
|
|
|
|
|
/**
|
|
|
* Converts the file size in bytes to human readable output.
|
|
|
- *
|
|
|
+ * <ul>
|
|
|
+ * <li>appends a size suffix, e.g. B, KB, MB etc.</li>
|
|
|
+ * <li>rounds the size based on the suffix to 0,1 or 2 decimals</li>
|
|
|
+ * </ul>
|
|
|
+ *
|
|
|
* @param bytes Input file size
|
|
|
* @return Like something readable like "12 MB"
|
|
|
*/
|
|
@@ -125,8 +131,9 @@ public class DisplayUtils {
|
|
|
result /= 1024.;
|
|
|
attachedsuff++;
|
|
|
}
|
|
|
- result = ((int) (result * 100)) / 100.;
|
|
|
- return result + " " + sizeSuffixes[attachedsuff];
|
|
|
+
|
|
|
+ return new BigDecimal(result).setScale(
|
|
|
+ sizeScales[attachedsuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedsuff];
|
|
|
}
|
|
|
|
|
|
/**
|