how to format a value in pt-br [duplicate]

1

I 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 question is how to do it the other way around.

    
asked by anonymous 25.02.2016 / 14:49

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;
    
25.02.2016 / 15:23