Counting file sizes together... Windows-style ;)

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
User avatar
nakkeli
Forum Newbie
Posts: 15
Joined: Thu Apr 10, 2008 1:18 am

Counting file sizes together... Windows-style ;)

Post by nakkeli »

I have listed all certain files into an array called $files. Then I'm counting their filesizes together and converting that into megabytes. But when I compare that with what windows says, it's different. Not that the size is different, only the way windows shows is different. Like in some cases windows uses only one decimal, and in some cases two. How can I change my script so it shows one or two decimals in certain cases like windows does? What causes this? And yes I know how I can change my script to show only one decimal, that is not what I'm after...

Example:
My code: 18,59 MB
Windows: 18,5 MB (size on disk)

Code: Select all

 
foreach ($files as $filename) {
  $filesizes = $filesizes + filesize($filename);
}   
$filesizes = number_format($filesizes/1048576, 2, ',', '.');
 
Post Reply