Format number from 3200 to 3,200 with PHP [duplicate]

-1

I have to transform values like:

3200
5000
10000
13000
100000

in

3.200
5.000
10.000
13.00
100.000

I tried to use the number_format function of PHP but could not do it correctly. How can I resolve this problem?

    
asked by anonymous 21.08.2016 / 00:04

1 answer

1

You can elaborate as follows:

function formata_valor($valor){
    if($valor!=NULL){
        echo number_format($valor, 0, ',', '.');
    } else {
        echo "Nenhum valor foi preenchido.";
    }
}
echo formata_valor("10000"); // output 10.000
  

Reference documentation: link

    
21.08.2016 / 00:27