Created
August 24, 2015 10:47
-
-
Save Kozlov-V/f6400652a355b67e269d to your computer and use it in GitHub Desktop.
File size to string
This file contains 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 getStringSizeLengthFile(long size) { | |
DecimalFormat df = new DecimalFormat("0.00"); | |
float sizeKb = 1024.0f; | |
float sizeMo = sizeKb * sizeKb; | |
float sizeGo = sizeMo * sizeKb; | |
float sizeTerra = sizeGo * sizeKb; | |
if(size < sizeMo) | |
return df.format(size / sizeKb)+ " Kb"; | |
else if(size < sizeGo) | |
return df.format(size / sizeMo) + " Mo"; | |
else if(size < sizeTerra) | |
return df.format(size / sizeGo) + " Go"; | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment