Hello, I’m connecting to the Mikrotik API in PHP, and when I get the rates they are in bytes format, so how do I convert them to MB or GB and so on..
I use the format bytes ($bytes / 1000) it can’t be done because the rate has pair values, so how to change it?
<td><?php echo formatBytes($rate,2);?> </td>
here is code fo format bytes :
function formatBytes($bytes, $decimal = null)
{
$satuan = [' Bytes', ' KB', ' MB', ' GB', ' TB'];
$i = 0;
while ($bytes > 1024){
$bytes /= 1024;
$i++;
}
return round($bytes, $decimal). '' . $satuan[$i];
}
The eror says : Notice: A non well formed numeric value encountered