PHP KB to MB converstion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

PHP KB to MB converstion

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP KB to MB converstion

Post by Celauran »

User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP KB to MB converstion

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

Re: PHP KB to MB converstion

Post by dmallia »

thanks alot :D thanks for you opinion pickle :)
Post Reply