summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-01-21 11:47:47 +0100
committerErich Eckner <git@eckner.net>2019-01-21 11:47:47 +0100
commitc073878b30c5d9098c8b780834ec7fce10eefc86 (patch)
tree3328d2968313ca17630e0524c8673fc8c0687895
parentf6d580ac95937df48bcc322032469828b9cc43e6 (diff)
downloadarchweb32-c073878b30c5d9098c8b780834ec7fce10eefc86.tar.xz
lib/helper.php: add_fancy_unit() new
-rw-r--r--lib/helper.php8
1 files changed, 8 insertions, 0 deletions
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);
+}