I have a utility function that will display a filesize in an appropriate form like Windows Explorer does, i.e; convert it to nearest KB, MB, GB etc. I wanted to know if the
@J_A_X has the best way to do this, however for the future, I suggest returning early when you find you have nested if...else...if
statements like you have.
public static function formatFileSize(bytes:int):String
{
if(bytes < 1024)
return bytes + " bytes";
bytes /= 1024;
if(bytes < 1024)
return bytes + " Kb";
bytes /= 1024;
if(bytes < 1024)
return bytes + " Mb";
bytes /= 1024;
if(bytes < 1024)
return bytes + " Gb";
return String(bytes);
}