Simple calculation to convert bytes to gb, mb and kb. In the below example we used round php function to roundup values. Initially started with the number in bytes and then converted it to GB, MB and KB.
<?php $byte=1073741824; if ($byte >= 1073741824) $byte_gb = round($byte / 1073741824 * 100) / 100 . " GB"; if ($byte >= 1048576) $byte_mb = round($byte / 1048576 * 100) / 100 . " MB"; if ($byte >= 1024) $byte_kb = round($byte / 1024 * 100) / 100 . " KB"; else $byte_byte = $byte . " bytes"; echo $byte_gb." ".$byte_mb." ".$byte_kb." ".$byte_byte; ?>
Cheers ..

Leave a Reply