-2
How to make a function to format a number of followers with php? Type on instagram
ex: 10000 = 10 k | 1000000 = 1 m
-2
How to make a function to format a number of followers with php? Type on instagram
ex: 10000 = 10 k | 1000000 = 1 m
-1
Other solution if you do not want to use number_format
why it rounds the value when formatting it.
<?php
function formatarSeguidores($numero, $numeroDivisao)
{
$numero = $numero / $numeroDivisao;
$numero = explode('.', $numero);
$numero[1] = isset($numero[1])
? substr($numero[1], 0, 1)
: 0;
if ($numero[1] == 0)
{
return $numero[0];
}
return implode(',', $numero);
}
function abreviarSeguidores($numero)
{
# Se seguidores na casa dos milhões.
if ($numero >= 1000000)
{
return formatarSeguidores($numero, 1000000) . 'm';
}
# Se seguidores na casa dos milhares.
else if ($numero >= 1000)
{
return formatarSeguidores($numero, 1000) . 'k';
}
return $numero;
}
Taking into account some Instagram profiles to simulate see the result:
echo abreviarSeguidores(4468758); #Será impresso: 4,4m
echo abreviarSeguidores(323951); #Será impresso: 323,9k
echo abreviarSeguidores(20440); #Será impresso: 20,4k
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
What if it’s 10200? Or 1000200? Or 1200150? Your question got kind of shallow.
– Sam
Another important thing: you have asked 6 questions and solved none. What is wrong?
– Sam
You have to show that the answers have solved your problem by marking them as accepted. See how in https://i.stack.Imgur.com/evLUR.png
– user60252