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

26 lines
761 B
PHP
Raw Normal View History

2013-10-02 08:12:58 +02:00
<?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;
}
}