Guest User

Untitled

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