This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/Rails/ActionView/Helper/Methods/Number.php
2013-10-02 01:12:58 -05:00

26 lines
761 B
PHP
Executable File

<?php
namespace Rails\ActionView\Helper\Methods;
trait Number
{
public function numberToHumanSize($number, array $options = array())
{
$size = $number / 1024;
if ($size < 1024) {
$size = number_format($size, 1);
$size .= ' KB';
} else {
if (($size = ($size / 1024)) < 1024) {
$size = number_format($size, 1);
$size .= ' MB';
} elseif (($size = ($size / 1024)) < 1024) {
$size = number_format($size, 1);
$size .= ' GB';
} elseif (($size = ($size / 1024)) < 1024) {
$size = number_format($size, 1);
$size .= ' TB';
}
}
return $size;
}
}