summaryrefslogtreecommitdiff
path: root/lib/helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/helper.php')
-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);
+}