index : website | |
Archlinux32 website - obsolete | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2019-01-21 11:47:47 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-01-21 11:47:47 +0100 |
commit | c073878b30c5d9098c8b780834ec7fce10eefc86 (patch) | |
tree | 3328d2968313ca17630e0524c8673fc8c0687895 /lib/helper.php | |
parent | f6d580ac95937df48bcc322032469828b9cc43e6 (diff) |
-rw-r--r-- | lib/helper.php | 8 |
diff --git a/lib/helper.php b/lib/helper.php index bb454f0..8296cd9 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -185,3 +185,11 @@ function site_is_reachable($url) { } return false; } + +function add_fancy_unit($value, $unit) { + $suffixes = array("z", "y", "a", "f", "p", "n", "ยต", "m", "", "k", "M", "G", "T", "P", "Y", "Z"); + if ($value==0) + return $value . " " . $unit; + $exponent = max(0,min(count($suffixes)-1,round(log(abs($value))/log(1024)-1))); + return sprintf("%.2f %s%s", $value / pow(1024,$exponent), $suffixes[8 + $exponent], $unit); +} |