Created
October 26, 2018 03:56
-
-
Save yung-yu/d96c49fdea91a4e96623a48e1663e6f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String readableFileSize(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(1024)); | |
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment