Skip to content

Instantly share code, notes, and snippets.

@tomgidden
Created January 7, 2015 11:50
Show Gist options
  • Save tomgidden/4b63dc7beb30f18fcc79 to your computer and use it in GitHub Desktop.
Save tomgidden/4b63dc7beb30f18fcc79 to your computer and use it in GitHub Desktop.
1024 => 1M, 1048576 => 1G, etc.
<?php
function geek_number_format($val, $withSpace=true, $suffix='')
{
$val = intval($val);
$units = array('', 'k', 'M', 'G', 'T', 'P', 'E');
while ($units and $val >= 1024) {
$val >>= 10;
array_shift($units);
}
return round(intval($val)).$units[0].($withSpace?' ':'').$suffix;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment