note 42885 modified in function.number-format by tomsommer
| From: | tomsommer@php.net | Date: | Mon, 28 Jun 2004 15:15:47 +0000 |
| Subject: | note 42885 modified in function.number-format by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72046@lists.php.net to get a copy of this message | ||
This function formats numbers 'human readable':
function byte_format($input, $dec=0)
{
$prefix_arr = array(" B", "K", "M", "G", "T");
$value = round($input, $dec);
$i=0;
while ($value>1024)
{
$value /= 1024;
$i++;
}
$return_str = round($value, $dec).$prefix_arr[$i];
return $return_str;
}
--was--
This function formats numbers 'human readable':
function byte_format($input, $dec=0)
{
$prefix_arr = array(" B", "K", "M", "G", "T");
$value = round($input, $dec);
$i=0;
while ($value>1024)
{
$value /= 1024;
$i++;
}
$return_str = round($value, $dec).$prefix_arr[$i];
return $return_str;
}
I made a small adjustment. Hope you don't mind. Notice the
'$i=0' and 'B' in the array. That way B is displayed too.
http://php.net/manual/en/function.number-format.php