Posted By

inkdeep on 04/21/08


Tagged

display format filesize numbers style


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

korzhik
apawson


Format (humanize) file byte size presentation in javascript


 / Published in: JavaScript
 

I use this in addition to the number_format (http://snipplr.com/view/5945/javascript-numberformat--ported-from-php/) snippit in SWFUpload to display the size of files a user is preparing to upload.

  1. function size_format (filesize) {
  2. if (filesize >= 1073741824) {
  3. filesize = number_format(filesize / 1073741824, 2, '.', '') + ' Gb';
  4. } else {
  5. if (filesize >= 1048576) {
  6. filesize = number_format(filesize / 1048576, 2, '.', '') + ' Mb';
  7. } else {
  8. if (filesize >= 1024) {
  9. filesize = number_format(filesize / 1024, 0) + ' Kb';
  10. } else {
  11. filesize = number_format(filesize, 0) + ' bytes';
  12. };
  13. };
  14. };
  15. return filesize;
  16. };

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: igitur on January 31, 2011

b = bit and B = byte

You need to login to post a comment.