Posted By

rondog on 03/16/10


Tagged

format bytes mb kb gb


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

adrianparr


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


 / Published in: ActionScript
 

URL: http://activeden.net/user/rondog?ref=rondog

this will convert bytes to a readable format with 2 decimal places

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

Report this snippet  

You need to login to post a comment.