Guest User

Untitled

a guest
Jul 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. function prettify_num($num){
  2.     $text = array(
  3.         0 => '',
  4.         1 => '',
  5.         2 => ' million',
  6.         3 => ' billion',
  7.         4 => ' trillion'
  8.     );
  9.  
  10.     $exp = 3 * floor( ( strlen( (string) $num ) - 1 ) / 3);
  11.     $rounded_num = round($num / pow(10, $exp), 1);
  12.     if (($rounded_num / 100) > 1) $rounded_num = round($rounded_num);
  13.     if (1 == ($exp / 3)) $rounded_num = number_format($rounded_num * 1000);
  14.     return $rounded_num . $text[$exp / 3];
  15. }
Add Comment
Please, Sign In to add comment