number format like K M in php code example
Example 1: numberformater php format to k and m
function number_format_short( $n ) {
if ($n > 0 && $n < 1000) {
$n_format = floor($n);
$suffix = '';
} else if ($n >= 1000 && $n < 1000000) {
$n_format = floor($n / 1000);
$suffix = 'K+';
} else if ($n >= 1000000 && $n < 1000000000) {
$n_format = floor($n / 1000000);
$suffix = 'M+';
} else if ($n >= 1000000000 && $n < 1000000000000) {
$n_format = floor($n / 1000000000);
$suffix = 'B+';
} else if ($n >= 1000000000000) {
$n_format = floor($n / 1000000000000);
$suffix = 'T+';
}
return !empty($n_format . $suffix) ? $n_format . $suffix : 0;
}
Example 2: numberformater php format to k and m
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
?>