Bytes to Readable format (bytes, kb, mb etc)

I thought this might come in handy for some people needing to convert bytes to a readable format. For example, I am making an uploader. This formats the bytes for you.


public static function readablizeBytes(bytes:uint):String
{
	var s:Array = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
	var e:Number = Math.floor( Math.log( bytes ) / Math.log( 1024 ) );
	return ( bytes / Math.pow( 1024, Math.floor( e ) ) ).toFixed( 2 ) + " " + s[e];
}

trace(readablizeBytes(50964241)); // 48.60 MB