$unit = Files::convertUnitFileSize(146432);
Result:
143 KB
public static convertUnitFileSize ( integer $size ) : string | ||
$size | integer | |
return | string |
public static function convertUnitFileSize($size)
{
$units = array(" B", " KB", " MB", " GB");
$calculatedSize = $size;
$unit = Arrays::first($units);
if ($size) {
$calculatedSize = round($size / pow(1024, $i = (int) floor(log($size, 1024))), 2);
$unit = $units[$i];
}
return $calculatedSize . $unit;
}
/** * @test */ public function shouldReturnWhenZeroPassed() { //when $unit = Files::convertUnitFileSize(0); //then $this->assertEquals('0 B', $unit); }