number_format
or do string parsing:function formatWithSuffix($input) { $suffixes = array('', 'k', 'm', 'g', 't'); $suffixIndex = 0; while(abs($input) >= 1000 && $suffixIndex < sizeof($suffixes)) { $suffixIndex++; $input /= 1000; } return ( $input > 0 // precision of 3 decimal places ? floor($input * 1000) / 1000 : ceil($input * 1000) / 1000 ) . $suffixes[$suffixIndex]; } echo formatWithSuffix(1000);
echo formatWithSuffix(100000);
Let me know if I missed any of your requirements:
Hit me with a comment!