AS3 Display BytesTotal as Megabytes (formatted)


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



Copy this code and paste it in your HTML
  1. var bytesTotal:int = loaderInfo.bytesTotal;
  2.  
  3. var kbFormatted:String = Math.floor(bytesTotal/1024)+" KB";
  4. var mbFormatted:String = (Math.floor(((bytesTotal/1024/ 1024)*100))/100)+" MB";
  5.  
  6. trace("kbFormatted: "+kbFormatted);
  7. trace("mbFormatted: "+mbFormatted);
  8.  
  9. // For example, if bytesTotal = 5024322 the output would be ...
  10. // kbFormatted: 4906 KB
  11. // mbFormatted: 4.79 MB

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.