* Added a percent() function
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sat, 16 Jul 2005 21:59:53 +0000 (21:59 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sat, 16 Jul 2005 21:59:53 +0000 (21:59 +0000)
includes/GlobalFunctions.php

index 07e7750..c0c9e0a 100644 (file)
@@ -1276,4 +1276,14 @@ function wfIncrStats( $key ) {
        }
 }
 
+/**
+ * @param mixed $nr The number to format
+ * @param int $acc The number of digits after the decimal point, default 2
+ * @param bool $round Whether or not to round the value, default true
+ * @return float
+ */
+function percent( $nr, $acc = 2, $round = true ) {
+       $ret = sprintf( "%.${acc}f", $nr );
+       return $round ? round( $ret, $acc ) . '%' : "$ret%";
+}
 ?>