[ create a new paste ] login | about

Link: http://codepad.org/nb89ze5J    [ raw code | output | fork ]

PHP, pasted on Mar 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
    function format_number($num) {
    	 if($num < 1000000) {
    	 	return number_format($num);
    	 } elseif ($num < 1000000000) {
    	 	return number_format($num/1000000, 2) . 'M';
    	 } else {
    	 	return number_format($num/1000000000, 2) . 'B';
    	 }
    }

echo format_number(123456000000) . "\n";
echo format_number(12345000000) . "\n";
echo format_number(123456000) . "\n";
echo format_number(123456) . "\n";
?>


Output:
1
2
3
4
123.46B
12.35B
123.46M
123,456


Create a new paste based on this one


Comments: