Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function prettify_num($num){
- $text = array(
- 0 => '',
- 1 => '',
- 2 => ' million',
- 3 => ' billion',
- 4 => ' trillion'
- );
- $exp = 3 * floor( ( strlen( (string) $num ) - 1 ) / 3);
- $rounded_num = round($num / pow(10, $exp), 1);
- if (($rounded_num / 100) > 1) $rounded_num = round($rounded_num);
- if (1 == ($exp / 3)) $rounded_num = number_format($rounded_num * 1000);
- return $rounded_num . $text[$exp / 3];
- }
Add Comment
Please, Sign In to add comment