Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Shorten long numbers to K/M/B?

function kmb($count, $precision = 2) {
if ($count < 1000000) {
// Anything less than a million
$n_format = number_format($count / 1000) . 'K';
} else if ($count < 1000000000) {
// Anything less than a billion
$n_format = number_format($count / 1000000, $precision) . 'M';
} else {
// At least a billion
$n_format = number_format($count / 1000000000, $precision) . 'B';
}
return $n_format;
}

echo kmb(272937);
> 273K

echo kmb(2729347);
> 2.73M

echo kmb(2729347874);
> 2.73B
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Shorten #long #numbers
ADD COMMENT
Topic
Name
8+6 =