Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Php :: php href variable in javascript alert 
Php :: php getUserStateFromRequest 
Php :: remove public from laravel 
Php :: wp-query 
Php :: curl multi exec get index 
Php :: php linkify text 
Php :: phpmailer valid cert 
Php :: $this meaning in codeigniter 
Php :: wordpress add block from single.php 
Php :: if($a $b){ echo "A B"; }else if($a < $b){ echo "A < B"; }else if($a != ""){ if($a == $b){ echo "A = B"; } } 
Php :: array_unshift php 
Php :: wp_query not have term 
Php :: how to disable the plugins and theme editor 
Php :: laravel media library regenerate 
Php :: add header image to woocomerce shop page 
Php :: Add Recent Posts by Category Using PHP 
Php :: updateorinsert laravel for large data 
Php :: php delete al lsession 
Php :: add variables to line in laravel notification 
Php :: current tab active on page reload in php 
Php :: answer to guzzle/psr7 undefine 
Php :: php decrement variable 
Php :: acf if image else display other image 
Php :: php like button counter 
Php :: Laravel Direct Browser Download 
Php :: lengthawarepaginator gives keys on page 2 
Php :: Jaygaah Free Shipping Woocommerce 
Php :: Laravel hasmany withSum() 
Php :: wordrpess debugg is off but still showing 
Php :: php zoom api start_time issue 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =