countformat

count_format
SYNOPSIS

count_format($n, $point='.', $sep=',')

DESCRIPTION
CODE
  1. function count_format($n, $point='.', $sep=',') {
  2.     if ($n < 0) {
  3.         return 0;
  4.     }
  5.  
  6.     if ($n < 10000) {
  7.         return number_format($n, 0, $point, $sep);
  8.     }
  9.  
  10.     $d = $n < 1000000 ? 1000 : 1000000;
  11.  
  12.     $f = round($n / $d, 1);
  13.  
  14.     return number_format($f, $f - intval($f) ? 1 : 0, $point, $sep) . ($d == 1000 ? 'k' : 'M');
  15. }

Comments

To add a comment, click here.