Skip to content

Instantly share code, notes, and snippets.

@Kozlov-V
Created August 24, 2015 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kozlov-V/f6400652a355b67e269d to your computer and use it in GitHub Desktop.
Save Kozlov-V/f6400652a355b67e269d to your computer and use it in GitHub Desktop.
File size to string
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