Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 2096

phpBB Custom Coding • Re: Count round thousand to a K style

$
0
0
Here is the function from the extension linked to above, just add it to the end of /includes/functions.php You'll also need to replace the values for the suffix because there is no language file. e.g. $suffix = 'K'; for thousands.

Code:

function number_format_short($n){if ($n >= 0 && $n < 10000){// 1 - 9999$n_format = floor($n);$suffix = '';}else if ($n >= 10000 && $n < 1000000){// 10k-999k$n_format = floor($n / 1000);$suffix = $this->language->lang('THOUSAND_SHORT_SUFFIX');}else if ($n >= 1000000 && $n < 1000000000){// 1m-999m$n_format = floor($n / 1000000);$suffix = $this->language->lang('MILLION_SHORT_SUFFIX');}else if ($n >= 1000000000 && $n < 1000000000000){// 1b-999b$n_format = floor($n / 1000000000);$suffix = $this->language->lang('BILLION_SHORT_SUFFIX');}else if ($n >= 1000000000000){// 1t+$n_format = floor($n / 1000000000000);$suffix = $this->language->lang('TRILLION_SHORT_SUFFIX');}$temp = $n_format . $suffix;return !empty($temp) ? $n_format . $suffix : 0;}

Now you can apply it to any number you want, for example in viewforum.php on line 971 find:

Code:

'REPLIES'=> $replies,
Replace with:

Code:

'REPLIES'=> number_format_short($replies),
Untested but it should work.

Statistics: Posted by thecoalman — Thu Feb 01, 2024 3:04 am



Viewing all articles
Browse latest Browse all 2096

Trending Articles