Page 1 of 1

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

Posted: Tue Jun 10, 2008 12:35 am
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, ',', '.');