Count For Human


/ Published in: ActionScript
Save to your folder(s)

Count For Human is a short cut for long digits to short human readable. E.g. 2045 the result is 2k.


Copy this code and paste it in your HTML
  1. function count_for_human($number) {
  2.  
  3. if($number>1000) {
  4.  
  5. $x = round($number);
  6. $x_number_format = number_format($x);
  7. $x_array = explode(',', $x_number_format);
  8. $x_parts = array('k', 'm', 'b', 't');
  9. $x_count_parts = count($x_array) - 1;
  10. $x_display = $x;
  11. $x_display = $x_array[0] . ((int) $x_array[1][0] !== 0 ? '.' . $x_array[1][0] : '');
  12. $x_display .= $x_parts[$x_count_parts - 1];
  13.  
  14. return $x_display;
  15.  
  16. }
  17.  
  18. return $number;
  19.  
  20. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.