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


/ Published in: ActionScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.