Last active
December 18, 2015 09:49
-
-
Save remoharsono/5764559 to your computer and use it in GitHub Desktop.
formatting into Kilobytes, Megabytes...//echo formatBytes(24962496);// 23.81M//echo formatBytes(24962496, 0);// 24M//echo formatBytes(24962496, 4);// 23.8061M
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatBytes($size, $precision = 2) | |
{ | |
$base = log($size) / log(1024); | |
$suffixes = array('', 'k', 'M', 'G', 'T'); | |
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment