2
How do I add the comma to the decimal place and the dot to the thousands.
Example:
$pagamento = R$ 1000.50;
/* trecho a fazer a operação */
echo $pagamento; //saída: "R$ 1.000,50"
2
How do I add the comma to the decimal place and the dot to the thousands.
Example:
$pagamento = R$ 1000.50;
/* trecho a fazer a operação */
echo $pagamento; //saída: "R$ 1.000,50"
7
Use the function number_format
for its amendment
$valor = 1000.50;
$valor = number_format($valor, 2 , ",", ".");
2
Dude
$moeda = 'R$ 1.550,52';
$valor = preg_replace('/[^0-9]/', '', $moeda);
$valor = bcdiv($valor, 100, 2);
$valor = strtr($valor, '.', ',');
echo $valor;
Or if you want to be separated by .
$moeda = 'R$ 1.550,52';
$valor = preg_replace('/[^0-9]/', '', $moeda);
$valor = bcdiv($valor, 100, 2);
$valor = strtr($valor, ',', '.');
echo $valor;
Browser other questions tagged php formatting replace number-format
You are not signed in. Login or sign up in order to post.
"Comma and period"
– Boi Programador
real, I set here to fit better what the young man needed.
– Diego Ananias
I opted for the simplest not to increase the lines of my code in my table
– Robert Sousa
The point is that if you guarantee that the value of
$moeda
will always be numeric, beauty! If not, this code above will help you!– Diego Ananias