ap_short_num( integer $num, integer $precision = 2 )
Description #
Convert number to 1K, 1M etc.
Parameters #
- $numinteger (Required) Number to convert.
- $precisioninteger (Optional) Precision. Default value: 2
Source #
File: includes/functions.php
function ap_short_num( $num, $precision = 2 ) {
if ( $num >= 1000 && $num < 1000000 ) {
$n_format = number_format( $num / 1000, $precision ) . 'K';
} elseif ( $num >= 1000000 && $num < 1000000000 ) {
$n_format = number_format( $num / 1000000, $precision ) . 'M';
} elseif ( $num >= 1000000000 ) {
$n_format = number_format( $num / 1000000000, $precision ) . 'B';
} else {
$n_format = $num;
}
return $n_format;
}
Expand full source code Collapse full source code View on GitHub: includes/functions.php:356
Add your comment