Search
 
SCRIPT & CODE EXAMPLE
 

PHP

numberformater php format to k and m

function shortNumber($num) 
{
    $units = ['', 'K', 'M', 'B', 'T'];
    for ($i = 0; $num >= 1000; $i++) {
        $num /= 1000;
    }
    return round($num, 1) . $units[$i];
}
Comment

numberformater php format to k and m

/**
 * @param $n
 * @return string
 * Use to convert large positive numbers in to short form like 1K+, 100K+, 199K+, 1M+, 10M+, 1B+ etc
 */
function number_format_short( $n ) {
	if ($n > 0 && $n < 1000) {
		// 1 - 999
		$n_format = floor($n);
		$suffix = '';
	} else if ($n >= 1000 && $n < 1000000) {
		// 1k-999k
		$n_format = floor($n / 1000);
		$suffix = 'K+';
	} else if ($n >= 1000000 && $n < 1000000000) {
		// 1m-999m
		$n_format = floor($n / 1000000);
		$suffix = 'M+';
	} else if ($n >= 1000000000 && $n < 1000000000000) {
		// 1b-999b
		$n_format = floor($n / 1000000000);
		$suffix = 'B+';
	} else if ($n >= 1000000000000) {
		// 1t+
		$n_format = floor($n / 1000000000000);
		$suffix = 'T+';
	}

	return !empty($n_format . $suffix) ? $n_format . $suffix : 0;
}
Comment

numberformater php format to k and m


<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."
";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."
";
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."
";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."
";
?>

Comment

PREVIOUS NEXT
Code Example
Php :: convertir date php en français 
Php :: Add current year on WordPress using Shortcode 
Php :: php insert in array 
Php :: selecting data from two tables in database php 
Php :: divide page in pdf with page break using php 
Php :: does xampp install php 
Php :: Best documentation tools for php 
Php :: update php local 
Php :: php remove html tag wrap 
Php :: jsondecode 
Php :: laravel query builder delete all 
Php :: $wpdb foreach 
Php :: laravel get route 
Php :: while loop laravel 
Php :: query log laravel 
Php :: php slice string by character 
Php :: create array of zeros php 
Php :: pagination using ajax 
Php :: dependency injection php 
Php :: laravel 6 use username instead of id 
Php :: Laravel whereHas with count 
Php :: php throw fatal error 
Php :: laraval routing 
Php :: php pass a function as a parameter 
Php :: php DateTime only date 
Php :: how to write php in script file 
Php :: php check if date between two dates 
Php :: wordpress basic auth 
Php :: How to add .active class to active menu item 
Php :: laravel env in js 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =