Here comes a PHP function to format numbers to nearest thousands such as Kilos, Millions, Billions, and Trillions with comma.
Function
function thousandsCurrencyFormat($num) {
if( $num > 1000 ) {
$x = round($num);
$x_number_format = number_format($x);
$x_array = explode(',', $x_number_format);
$x_parts = array('k', 'm', 'b', .