Depending on the number of bytes selects the maximum allowable value.
function bytesConverting($bytes) { $s = ['байт', 'Кбайт', 'Мбайт', 'Гбайт', 'Тбайт', 'Пбайт']; $e = floor(log($bytes)/log(1024)); return sprintf('%.2f ' . $s[$e], ($bytes/pow(1024, floor($e)))); } How are things from the point of view of algebra? Is it possible to simplify \ change \ have a better option?