[Openfirst-cvscommit] SF.net SVN: openfirst: [207] trunk/src/includes/functions.php
Brought to you by:
xtimg
|
From: <ast...@us...> - 2006-07-04 14:04:50
|
Revision: 207 Author: astronouth7303 Date: 2006-07-04 07:04:45 -0700 (Tue, 04 Jul 2006) ViewCVS: http://svn.sourceforge.net/openfirst/?rev=207&view=rev Log Message: ----------- Remove trailing 0's/decimal in ofFormatSize(). Modified Paths: -------------- trunk/src/includes/functions.php Modified: trunk/src/includes/functions.php =================================================================== --- trunk/src/includes/functions.php 2006-06-28 21:10:38 UTC (rev 206) +++ trunk/src/includes/functions.php 2006-07-04 14:04:45 UTC (rev 207) @@ -69,21 +69,39 @@ * Uses 1024 definition (1 KB = 1024 B) */ function ofFormatSize($size) { + $base = 1024; ## Set to 1000 if you want SI compliance + $units = array( + 'B', + 'KB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB', + 'XB', + false, + 'VB' + ); + + $units = array_reverse($units, true); + reset($units); + while (list($pow, $unit) = each($units)) { + if ($unit === false) continue; + if ($size >= pow($base, $pow)) { + $unitsize = $size/pow($base, $pow); + $unitsize = rtrim($unitsize, '0'); + if (substr($unitsize, -1) == '.') $unitsize = substr($unitsize, 0, -1); + $rv = number_format($unitsize, 2, '.', ''); + $rv = rtrim($rv, '0'); // Remove trailing 0's + $rv = rtrim($rv, '.'); // Remove trailing decimal (if any) + return $rv.' '.$unit; + } + } +} +function ofFormatSize($size) { $base = 1024; - $units = array( - 'B', - 'KB', - 'MB', - 'GB', - 'TB', - 'PB', - 'EB', - 'ZB', - 'YB', - 'XB', - false, - 'VB' - ); $units = array_reverse($units, true); reset($units); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |