Posted By

tylerhall on 11/30/-1


Tagged

scott textmate bytesize math human readable


Versions (?)

Who likes this?

22 people have marked this snippet as a favorite

bomberstudios
daniel
Roshambo
neverwolf
ndegruchy
irdial
vaaaska
blakeb
fael
marteki
chucktrukk
Firemarble
mb
Keef
nicogranelli
JimiJay
dantreacy
mecha
SevenLayersDesign
tasmanweb
ringo380
tux-world


Make bytesizes human readable


 / Published in: PHP
 

  1. function human_readable($val, $round = 0)
  2. {
  3. $unit = array('','K','M','G','T','P','E','Z','Y');
  4. while($val >= 1000)
  5. {
  6. $val /= 1024;
  7. array_shift($unit);
  8. }
  9. return round($val, $round) . array_shift($unit) . "B";
  10. }

Report this snippet  

You need to login to post a comment.