diff options
author | Simon Rettberg | 2022-11-15 17:20:20 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-11-15 17:20:20 +0100 |
commit | 74f1db5c2670f7247abc8ea8bbb9b171c9e88f6a (patch) | |
tree | d17382ebfcebaa38df34adac61d37eff45913d10 /inc/dictionary.inc.php | |
parent | [statistics] Fix potential invalid array access (diff) | |
download | slx-admin-74f1db5c2670f7247abc8ea8bbb9b171c9e88f6a.tar.gz slx-admin-74f1db5c2670f7247abc8ea8bbb9b171c9e88f6a.tar.xz slx-admin-74f1db5c2670f7247abc8ea8bbb9b171c9e88f6a.zip |
[inc/Dictionary] Add locale-aware number formatting method
Diffstat (limited to 'inc/dictionary.inc.php')
-rw-r--r-- | inc/dictionary.inc.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index e366207f..4c98c63b 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -64,6 +64,31 @@ class Dictionary } /** + * Format given number using country-specific decimal point and thousands + * separator. + * @param float $num Number to format + * @param int $decimals How many decimals to display + */ + public static function number(float $num, int $decimals = 0): string + { + static $dec = null, $tho = null; + if ($dec === null) { + if (LANG === 'de') { + $dec = ','; + $tho = '.'; + } elseif (LANG !== 'en' && file_exists("lang/" . LANG . "/format.txt")) { + $tmp = file_get_contents("lang/" . LANG . "/format.txt"); + $dec = $tmp[0]; + $tho = $tmp[1]; + } else { + $dec = '.'; + $tho = ','; + } + } + return number_format($num, $decimals, $dec, $tho); + } + + /** * Get complete key=>value list for given module, file, language * * @param string $module Module name |