PHP Human Readable filesize script always returns a "B" : <p>After thinking mine was in error, </p>

<p>I found LOT AT LOTS of scripts the do this:
<a href="https://gist.github.com/liunian/9338301" rel="nofollow noreferrer">https://gist.github.com/liunian/9338301</a></p>

<p>And there are several here at S.O. I used, but had the same annoying "B" as a size.</p>

<p>This issue seemed to rear it's ugly head when I switched to php v7.xxx
First issues is I have to typcase a floated number (or double) or else I get a 
"A non well formed numeric value encountered"
After some research, apparently this is <a href="https://bugs.php.net/bug.php?id=73468" rel="nofollow noreferrer">NOT a bug</a>. At least that is how I read it.</p>

<p>So after typcasting it, the error goes away but the value returned is always a "B'
filesize = 87.5B (when it should be MB or GB).</p>

<p>I am pretty sure Javascript will work, but would rather keep it with php.</p>

<p>Thanks for looking</p>

<p>current live script that is producing a "B" only</p>

<pre><code> public function readableBytes($size,  $type='pc') { //ignore the pc - it is for something else - disabled for debugging
        $size = (double)$size;
        static $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
        $step = 1024;
        $i = 0;
        while (($size / $step) &gt; 0.9) {
            $size = $size / $step;
            $i++;   
        }
        return round($size, 2).$units[$i];
    }// function readbbleBytes
</code></pre>
