Page 1 of 1

PHP KB to MB converstion

Posted: Fri Nov 25, 2011 11:28 am
by dmallia
So I'm doing a php script to list the files in a particular folder. I want to display the size in MB and here's the converstion code

Code: Select all

$filesize = filesize("./images/". $filecrc);
$filesize = ($filesize / 1048576);
now i have a file that is 650KB and when the php script converts it it becomes 0.6349515914917. Someone know how i can display only 2 decimal places(displays only 2 numbers after the point 0.63)?

Thanks

Re: PHP KB to MB converstion

Posted: Fri Nov 25, 2011 11:38 am
by Celauran

Re: PHP KB to MB converstion

Posted: Fri Nov 25, 2011 12:06 pm
by pickle
You're actually converting between KiB and MiB: http://en.wikipedia.org/wiki/Kibibyte

I'd suggest sticking with base 10 as that's what most OSs do, and what most users are used to.

Re: PHP KB to MB converstion

Posted: Fri Nov 25, 2011 12:45 pm
by dmallia
thanks alot :D thanks for you opinion pickle :)