From c073878b30c5d9098c8b780834ec7fce10eefc86 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 21 Jan 2019 11:47:47 +0100 Subject: lib/helper.php: add_fancy_unit() new --- lib/helper.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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); +} -- cgit v1.2.3-70-g09d2