DecimalFormat df = new DecimalFormat("###.##");
float f;
if (size < 1024 * 1024) {
f = (float) ((float) size / (float) 1024);
return (df.format(new Float(f).doubleValue())+"KB");
} else {
f = (float) ((float) size / (float) (1024 * 1024));
return (df.format(new Float(f).doubleValue())+"MB");
}
System.out.println(fileSize(new Long(274947)));
System.out.println(fileSize(new Long(1197340))); |