how to format a value in en

Asked

Viewed 143 times

1

Galera currently use the following code in php to format a value in PT-BR (22.222,22)

// Colocar valor no padram 0,000,000.00 
$valor_antigo = "22222.22";
$valor = number_format($valor_antigo, 2, ',', '.');

My doubt and how to do it the other way.

1 answer

1

The solution is this:

$valores = '530222077.99';


$formatter = new NumberFormatter('pt_BR', NumberFormatter::CURRENCY);
$valores = $formatter->formatCurrency($valores, 'BRL');


echo $valores;

echo "<br><hr><br>";


$valor_puro = $formatter->parseCurrency($valores, $valor_puro);


echo $valor_puro;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.