PHP shorten numbers to k, m, b php - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution
join us

shorten numbers to K, M, B using php


 788

Show ResultPHP


2

<?php
function convert_to_K_M_B($number, $precision = 1, $divisors = null) {

if (!isset($divisors)) {
$divisors = array(
pow(1000, 0) => '', // >1000
pow(1000, 1) => 'K', // Thousand
pow(1000, 2) => 'M', // Million
pow(1000, 3) => 'B', // Billion
);
}


foreach ($divisors as $divisor => $shorthand) {
if (abs($number) < ($divisor * 1000)) {

break;
}
}

return number_format($number / $divisor, $precision) . $shorthand;
}
?>

<?php

echo convert_to_K_M_B(100652);

?>


By        
The power of the user (%)
4%



The most helpful PHP solutions

detect browser phpdetect browser phpPHP

Click to see more ...

  4.6K     408

create QR code phpcreate QR code phpPHP

Click to see more ...

  3K     289

create relative date phpcreate relative date phpPHP

Click to see more ...

  2.1K     264

drag and drop upload file using phpdrag and drop upload file using phpPHP

Click to see more ...

  2.7K     253

delete array item phpdelete array item phpPHP

Click to see more ...

  2.4K     245

detect ie phpdetect ie phpPHP

Click to see more ...

  1.6K     213

detect speed internet phpdetect speed internet phpPHP

Click to see more ...

  1.6K     198

get current url phpget current url phpPHP

Click to see more ...

  1.7K     197

get meta tag phpget meta tag phpPHP

Click to see more ...

  1.4K     193

Get real client country using php ?Get real client country using php ?PHP

Click to see more ...

  1.4K     181

Welcome aboard!
We are happy you are here and
wish you good net-raft!