Convert any amount into sort form in thousand, million, billion then in this post we have shared simple php function to convert any big amount to it’s sort form.
In this tutorial I will show you how to convert any number into sort format in thousand, million, billion then in this post we have shared simple php function to convert any number to it's sort form. Like you have price list data and you don’t want to display full price amount in number form then you can simply pass value into below function and it'll convert you price amount to sort form like (Ex: 1K, 10M, 15B etc).
function amount_format($n) {
// first strip any formatting;
$n = (0+str_replace(",", "", $n));
// is this a number?
if (!is_numeric($n)) return false;
// now filter it;
if ($n > 1000000000000) return round(($n/1000000000000), 2).'T';
elseif ($n > 1000000000) return round(($n/1000000000), 2).'B';
elseif ($n > 1000000) return round(($n/1000000), 2).'M';
elseif ($n > 1000) return round(($n/1000), 2).'K';
return number_format($n);
}
echo amount_format('1704'); //1.7K
echo amount_format('15000000'); //15M
echo amount_format('1020440500'); //1.02B
echo amount_format('1400005600040'); //1.4T